What is JSON?🤔
JSON (JavaScript Object Notation) is a lightweight data-interchange format.
JSON is easy for humans to read and write, yet it is efficient enough for computers to handle.
JSON is commonly used for transmitting data in web applications (e.g., sending some data from the server to the client, or passing state information between the two) and for serializing structured data into a string representation.
It can be used to represent numbers, strings, booleans, arrays, objects, and raw bytes in a standardized way.
JSON is often used to output data in the Web API's response body.
Advantages of using JSON
JSON is an open standard that enables data to be exchanged between applications without the need for a middleman.
JSON is easy for humans to read and write, which makes it ideal for data exchange between different applications.
JSON is more compact than XML, and therefore easier to transmit.
It is supported by all programming languages.
It can be used on all platforms.
It is a light weight database standard, so data transmission is fast.
Where JSON is used?
JSON is used as the data format for many web services and APIs, such as GitHub, Netflix, Twitter and Facebook
Mobile Applications
Gaming API's
Data types supported
- String
- Number
- Arrays
- Null
- Boolean
- Object
JSON methods in JavaScript
JSON.parse(): Takes JSON string and convert into JavaScript object.
JSON.stringify(): Convert JavaScript object JSON into JSON string useful while sending over the network.
Syntax and Example
{
"squadName": "Super hero squad",
"homeTown": "Metro City",
"formed": 2016,
"secretBase": "Super tower",
"active": true,
"members": [
{
"name": "Molecule Man",
"age": 29,
"secretIdentity": "Dan Jukes",
"powers": ["Radiation resistance", "Turning tiny", "Radiation blast"]
},
{
"name": "Madame Uppercut",
"age": 39,
"secretIdentity": "Jane Wilson",
"powers": [
"Million tonne punch",
"Damage resistance",
"Superhuman reflexes"
]
},
{
"name": "Eternal Flame",
"age": 1000000,
"secretIdentity": "Unknown",
"powers": [
"Immortality",
"Heat Immunity",
"Inferno",
"Teleportation",
"Interdimensional travel"
]
}
]
}
Top comments (4)
Not that I am particularly a fan of XML which is probably the second most popular data transfer mechanism, but JSON is missing a few key elements that make working with XML easier
1) no ability to add annotations and comments. JSON is all data; this is changing with the JSON5 standard but it is not widely adopted and is a breaking change
2) no data type definitions. With XML you can publish a DTD document that specifies what nodes are required, optional, repeatable etc. You can then map this to the target document and validate that it is in the right format
3) no automated transformation. With XML you can also create an XLST file to automatically transform the incoming structure to another structure; removing and combining nodes, reordering data, adding aggregate values etc.
I'm not saying don't use JSON just be aware it has some limitations and there are other options
Hi, Aaron Reese
Thanks for sharing your knowledge.
let's talk about XML disadvantages
Like any good technology, XML does not try to be the solution to every problem.
There are some things it just cannot do well, and it would be foolish to try to force it to do them.
The foremost requirement of XML is that it be universally accessible, a lowest common denominator for applications. This necessarily throws out many optimizations that are necessary in some situations.
Let’s review some of these limitations:
1.
2.
In fact, I'm not a fan of XML or JSON
I'm a fan of any technology to do what I want to build with it.
Here you and I explain what is XML limitations and what is JSON limitations.
Anyone now can choose what is better.
Thanks again
thanks
You're welcome 😎