What is JSON - Working With JSON - MongoDB Tutorial



What is JSON ?

  • JSON is known as JavaScript Object Notation.
  • It provides a format for transporting and storing data.
  • In logical manner, it is a lightweight human readable collection of data that can be accessed.
  • From the user input it stores and generates the data. It can also verify and build the data.
  • It transfers the data from server to client, client to server, server to server.
  • It is easy to understand and self-describing. It is a lightweight data interchange format.

Syntax Rules

  • Data is in name/value pairs.
MongoDb
  • Data is separated by commas.
MongoDb
  • Curly braces hold objects.
MongoDb
  • Square brackets hold arrays
MongoDb

For example

MongoDb

Sample Code

<!DOCTYPE html>
        <html>
    <body>
      <h2>Create Object from JSON String</h2>
      <p id="demo"></p>
      <script>
        let text = '{"employees":[' + '{"firstName":"Nandha","lastName":"Kishore" },' + '{"firstName":"Venkat","lastName":"prabu" },' + '{"firstName":"Nizar","lastName":"Mohammed" }]}';
        const obj = JSON.parse(text);
        document.getElementById("demo").innerHTML = obj.employees[1].firstName + " " + obj.employees[1].lastName;
      </script>
    </body>
  </html>

Output

MongoDb

MongoDB Insert Collection

MongoDb

MongoDB Select

MongoDb

MongoDB Select Pretty

MongoDb

Features of JSON

MongoDb
  • Simplicity
    • It is easy to understand.
  • Openness
    • It is receptive to new opinions, arguments, or ideas.
  • Self-Describing
    • It is the act or an instance of describing oneself.
  • Internationalization
    • It may be readily consumed across multiple countries.
  • Extensibility
    • It allows the addition of new functionalities or capability.
  • Interoperability
    • It is ability to use or work with the parts or equipment of another system.

Advantages of JSON

MongoDb
  • Fast and sufficient
    • It shares a lot of similarities with JavaScript, due to its JavaScript inspired syntax.
    • They don’t know what type of data to expect, while it can be interrupted by any application.
    • In Key/value pair, A colon separates the name of the field from its value.
    • It becomes easy to understand. It is much faster than XML.
  • Responsive
    • While using JSON data can be easily parsed. Parsing doesn’t require any extra code.
    • Response increases because it is a server-side coding.
    • JSON has become one of the most widely accepted data exchange formats in result. It allows client to receive files quickly.
  • Key/value Pair Approach
    • The key and values are enclosed with double quotation marks (““).
    • A comma (,) and a colon (:) separate them, because they are separate characters.
    • It simplifies writing and reading.
  • Data Sharing
    • It is notable for its ability to share data to its other functions.
    • In order to exchange data, they set up a connection between front end and back-end language.
    • In JSON it is quite easy to serialize and de-serialize structured data.
    • The front-end language has to be transacted into JSON text in order to serialize.
  • Extensive browser support
    • Compare to any specific application, JSON data format is independent.
    • Most programming languages support JSON through functions or libraries.

Disadvantages of JSON

MongoDb
  • No date data type
    • Dates are not supported. It provides many different data types such as number, array, object, Boolean, string, and null.
    • It requiring developers to look for alternatives, because Date data types are absent from JSON.
    • For representing Date, string data type is one option.
    • The XSLT template allows you to easily do this in XML format.
  • Verbose
    • We have emphasized JSON codes compactness and ease and it might surprise you to see verbosity on this list.
    • This characteristic becomes disadvantage in particular while working on special projects.
    • JSON code is imperceptible to most software, due to its lack of conciseness.
  • Lack of comments
    • The comments are crucial, in order to understand. It can only allow limited comments.
    • As input some JSON libraries doesn’t accept the comments.
    • It won’t be easy to figure out the data when its sure in other words.
  • Less secure
    • In this still some browsers does not offer native JSON support, despite the majority having it.
    • JavaScript object is created by parsing JSON.
    • If you choose to use this function you may increase your application security risks.
    • These risks are similar to arise when the application takes user input.


Related Searches to What is JSON - Working With JSON - MongoDB Tutorial