Open In App

What is JSON text ?

Improve
Improve
Like Article
Like
Save
Share
Report

The Javascript Object Notation(JSON) is used to transfer or exchange information on the internet. JSON is just the plain text written as a javascript object. There exist several key-value pairs which represent some useful information. 

The important thing to keep in mind is, although the JavaScript comes in the full form of JSON, it is not limited to the JavaScript programming language instead it’s just a representation of some information that can be used anywhere in any programming language, library, or framework. Several programming environments have features to parse and generate the JSON data.

Some Properties of JSON:

  • It is easy to write and compact, self-describing.
  • It is both machine and human-understandable.
  • It is purely a string.
  • It can be a number, a string, a value, an object, or an array, But the most used are the last two.
  • Unlike the javascript object, the keys in JSON cannot contain the methods, only properties are allowed.
  • Only Double quotes are used to wrap the string or property in the JSON.
  • We can create the JSON file by writing the .json extension.
  • The Media type is application/json.

Use Cases of JSON:

  • In web application to transfer data from server to client and vice versa.
  • In testing the REST APIs, via any software like Postman.
  • To exchange data between two or more different programming environments.
  • It is used to transmit and receive structured data on the network.

Examples

Object JSON: This is the simple object containing the information of geeks for geeks.

Javascript




{
  "name": "GeeksforGeeks",
  "about": "A portal for Computer Science Geeks to read the articles related",
  "additionalDescription": "It also provides some Courses",
  "founder": "Sandeep Jain",
  "mail": "feedback@geeksforgeeks.org",
  "address": "Sector-136, Noida, Uttar Pradesh - 201305"
}


Array JSON: This is a simple JSON of an array containing the list of the few courses of geeks for geeks.

Javascript




[
    {
      "name": "Data Structures with C++ Live",
      "description": "A course specially designed for C++ enthusiasts",
      "whatYouWillLearn": [
        "Mastering DS from basic to advanced level",
        "Solving problems which are asked in product-based companies",
        "How to become a strong and efficient problem solver",
        "Enhance your problem-solving ability"
      ]
    },
    {
      "name": "JAVA Backend Development - Live",
      "description": "Learn backend development with Hibernate, RESTful APIs",
      "whatYouWillLearn": [
        "Redis & Kafka with Spring Boot",
        "Advanced Java",
        "Spring / Spring Boot",
        "Micro-services & related technologies used to build Java-based web applications"
      ]
    },
    {
      "name": "System Design - Live",
      "description": "LIVE System Design classes for individuals looking to crack SDE job",
      "whatYouWillLearn": [
        "How to design scalable systems",
        "Tips to crack system design interviews",
        "The intensity of the interview & how to manage your time",
        "Real-world example questions like designing system of Uber, Twitter etc.",
        "How to apply theory into application in real-time"
      ]
    }
  ]


JSON in Javascript: In javascript, we can simply create the JSON with the inbuilt stringify() method of javascript.

Javascript




<script>
    const myObject = {
        a:1,
        b:"Some Text",
        c:[
            {
            key1:"property1"
            },
            {
            key2:"property2"
            },
            {
            key3:"property3"
            }
        ]
    };
console.log(JSON.stringify(myObject));
</script>


Output:- When we open the index.html file containing the above code snippet in the browser, this will happen in the console. 



Last Updated : 28 Dec, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads