Solved

json format text only

Posted on 2016-09-23
4
75 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with Syntax 9 26
servlet filter example 37 42
How can I get this SlideToggle to behave? 6 18
arguments to jar 5 14
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

910 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

21 Experts available now in Live!

Get 1:1 Help Now