Solved

json format text only

Posted on 2016-09-23
4
83 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 (Megan)
zephyr_hex (Megan) earned 250 total points
ID: 41812900
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
ID: 41813661
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
ID: 41813873
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
ID: 41813943
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I enable / disable a text box with a checkbox 3 19
printf performancy 11 43
key press alert 2 19
Java syntax, or is it Selenium 6 13
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

809 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