Solved

json format text only

Posted on 2016-09-23
4
64 Views
Last Modified: 2016-09-25
Hi,

I am reading about json at below url

http://www.w3schools.com/json/

I have not understood below statement
* JSON uses JavaScript syntax, but the JSON format is text only, just like XML.
what it mean by json format is text like XML.
is XML is text only. json format text means what? we cannot use numbers?
please advise
0
Comment
Question by:gudii9
  • 2
4 Comments
 
LVL 42

Assisted Solution

by:zephyr_hex
zephyr_hex earned 250 total points
Comment Utility
JSON follows a certain syntax pattern which symbolizes an hierarchical structure, similar to XML.  In XML you have tags as delimiters.  In JSON you have different delimiters.

XML:
<Parent>
   <Child>Stuff</Child>
</Parent>

Open in new window


JSON
{
  "Parent": { "Child": "Stuff" }
}

Open in new window


JSON does support some data types
For example, a number:
{
  "Parent": { "Child": 47 }
}

Open in new window

0
 
LVL 27

Accepted Solution

by:
BigRat earned 250 total points
Comment Utility
The difference is that in Javascript object construction by curly brackets can be performed with explicit key names, whereas in JSON format these name MUST be textual :-

Javascript : { field1: "the good rat", field2: "the bad mouse" }
JSON         : { "field1": "the good rat", "field2": " The bad mouse" }

Notice the quotes around the field names.
0
 
LVL 7

Author Comment

by:gudii9
Comment Utility
whereas in JSON format these name MUST be textual :-

Javascript : { field1: "the good rat", field2: "the bad mouse" }
JSON         : { "field1": "the good rat", "field2": " The bad mouse" }

Notice the quotes around the field names.

i see.

what is the advantage of json key name text formatting like textual i,e ""

please advise
0
 
LVL 27

Expert Comment

by:BigRat
Comment Utility
There is no advantage. It is done to simplify things, since in Javascript the "field name" can be a number or a boolean value. Also note that you must always use double quotes and not single quotes, which are allowed in javascript.

https://en.wikipedia.org/wiki/JSON
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

We will take a look at the d3.js library for visualizations.  I will provide a walkthrough of a short bar graph example as well as introduce you to the d3.js API.  We also will explore links of other examples and further information regarding SVG's.
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now