Solved

json format text only

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

730 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