JavaScript Object Notation is a schema-less, text-based representation of structured data, based on key-value pairs. JSON is derived from JavaScript and commonly, but not exclusively, used to exchange information between web clients and web servers through APIs..
Today JSON is the format of choice for almost every web service.
Relational databases like PostgreSQL and MySQL now support for storing and querying JSON data. NoSQL databases like MongoDB and Neo4j also support JSON.
Below I'll take a quick look at JSON. Let’s start with an example:
Above structure clearly defines some attributes of an entity. It includes a first and last name ...etc. The structure may be passed from a server to a web browser or a mobile application, which will then perform some action such as displaying/saving it for later reference.
JSON value types: strings, numbers, booleans, lists, objects, and null.
npm Installation
Using npm :
- Get node.
npm install -g json
Manual method:
- Get the 'json' script. Then put it on your PATH somewhere (it is a single file with no external dependencies). Ex:
cd ~/bin curl -L https://github.com/trentm/json/raw/master/lib/json.js > json chmod 755 json
Then check "json" on your PATH:
$ json --version
json 9.0.0
Why should I use JSON?
The data was transferred in XML format in old applications, and XML was verbose and difficult to manage in JavaScript. JavaScript already had objects, which are a way of expressing data within the language. JSON was much easier for people to read and for browsers to parse. Soon web developers began to prefer JSON over XML.
Now JSON is the standard for exchanging data between web and mobile clients and back-end services.
When should I use JSON?
- If you’re writing software that communicates with a browser or native mobile application, you should use JSON as the data format.
- In the case of server-to-server communication JSON isn’t a bad choice.
- If you’re using NoSQL databases, you’re pretty much stuck with whatever the database gives you. In relational databases that support JSON as a type, a good rule of thumb is to use it as little as possible.
- You can expect a performance hit when querying for properties within those JSON objects.
- Its simple design and flexibility make it easy to read and understand, and in most cases, easy to manipulate in the programming language of your choice.
- The lack of a strict schema enables flexibility of the format, but that flexibility sometimes makes it difficult to ensure that you’re reading and writing JSON properly.
- Choosing XML over JSON when building a new web service is a red flag likely to turn away talent, because it indicates a lack of interested in staying relevant.
Limits of JSON
Here are the five main limitations:
- No schema.
- Only one number type.
- No date type.
- No comments.
- Verbosity.
Comments