What Is JSON?
What Is JSON?
Introduction
In a world inundated with data, it is becoming more important to know how to work with a variety of data. As programmers, we need to be able to transfer our populated data structures from any language we choose to a format that is recognizable and readable by other languages and platforms. Fortunately for us, there exists such a data-exchange format.
What is JSON?
JSON, orJavaScriptObject Notation, is a popular, language-independent, standard format for storing and exchanging data. Adopted byECMA International, an industry association founded in 1961 to standardize information and communication systems,JSONhas become the de facto standard that facilitates storing and sending data between allprogramming languages.
Common Uses of JSON
JSON is heavily used to facilitate data transfer in web applications between a client, such as a web browser, and a server. A typical example where such data transfer occurs is when you fill out a web form. The form data is converted from HTML to JavaScript objects to JSON objects and sent to a remote web server for processing. These transactions could be as simple as entering a search engine query to a multi-page job application.
When companies make their data public for other applications, like Spotify sharing its music library or Google sharing its map data, the information is formatted in JSON. This way, any application, regardless of language, can collect and parse the data.
Some of the popular web APIs that utilize JSON in data exchanges are:
- Google Maps
- Google Auth 2.0 Authentication
- Facebook Social Graph API
- Spotify Music Web API
- LinkedIn Profile API
JSON Syntax
Since JSON is derived from the JavaScriptprogramminglanguage, its appearance is similar to that of JavaScript objects.
A sample JSON object is represented as follows:
{ "student": { "name": "Rumaisa Mahoney", "age": 30, "fullTime": true, "languages": [ "JavaScript", "HTML", "CSS" ], "GPA": 3.9, "favoriteSubject": null }}
Copy to clipboard
{ "student": { "name": "Rumaisa Mahoney", "age": 30, "fullTime": true, "languages": [ "JavaScript", "HTML", "CSS" ], "GPA": 3.9, "favoriteSubject": null }}
Note the following syntax rules for JSON:
- The curly braces,{}, hold objects.
- The square brackets,[], hold arrays.
- Data is stored in key:value pairs separated by a colon,:.
- Every key:value pair is separated from another pair by a comma,,. Similarly, every item in an array is delimited by a comma.Trailing commasare forbidden.
- Property names in JSON must be wrapped in double quotes,"", even though JavaScript names are not held by this stringency.
- JSON does not support comments.
The following object would be valid JavaScript, but is not valid JSON:
{ "student": { name: "Rumaisa Mahoney", "age": 30, "fullTime": true, "languages": [ "JavaScript", "HTML", "CSS", ], "GPA": 3.9, 'favoriteSubject': null }}
Copy to clipboard
{ "student": { name: "Rumaisa Mahoney", "age": 30, "fullTime": true, "languages": [ "JavaScript", "HTML", "CSS", ], "GPA": 3.9, 'favoriteSubject': null }}
- Thenameproperty is not wrapping double quotes.
- The"languages"array has a trailing comma after the final item,"CSS".
- 'favoriteSubject'uses single quotes instead of double quotes.
JSON Data Types
A JSON data type must be one of the following:
- string (must be wrapped in double quotes, like property names)
- number (integer or floating point)
- object (key:value pair)
- array (comma-separated values)
- boolean (trueorfalse, without quotes)
- null
Try to find all the data types in this JSON example:
{ "student": { "name": "Rumaisa Mahoney", "age": 30, "fullTime": true, "languages": [ "JavaScript", "HTML", "CSS" ], "GPA": 3.9, "favoriteSubject": null }}
Copy to clipboard
Notably, JSON doesn’t cover every data type. Types that are not represented in JSON, such as dates, can be stored as a string and converted to a language-specific data structure. Here’s an acceptable internationally-recognized date format inISO 8601:
"2014-01-01T23:28:56.782Z"
This format contains parts which resemble a date and time. However, as a string, it is hard for a programming language to use as is. Conveniently, every programming language has built-in JSON facilities to convert this string into a more readable and usable format, such as:
Wed Jan 01 2014 13:28:56 GMT-1000 (Hawaiian Standard Time)
This pretty much covers the basic description of JSON, its popularity, and its syntax. Congratulations on reaching this milestone!
'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'
Complete Payment to Unlock Full Guide & Source Code
You are viewing the 30% preview. Join TopCourseAI Pro to unlock the remaining 70% of this article, unblur all code snippets, and gain full access to all 412 technical projects and guides.
Ready to access the complete step-by-step tutorial?
Gain full unhindered access to all 412 technical projects and guides, unblur all source code snippets, and download runnable scripts.
Related Blueprints & Guides
View all 166 →Accessibility on the Platform
Codecademy is committed to providing a high-quality learning experience for all learners. That includes accommodating different usage forms such as auditory, motor, or visual restrictions, limited hardware, or other acce...
Web developmentAffordances, Signifiers, and Clickability
For users on the web, the mouse click is perhaps the most fundamental human-computer interaction. The webbecamethe web partially through the power ofhypertext, or text in one document that links to other documents or res...
Web developmentAuthentication and OAuth
Authenticationis the process used by applications to determine and confirm identities of users. It ensures that the correct content is shown to users. More importantly, it ensures that incorrect content is secured and u...
Ready to build production-grade AI systems?
Enjoyed this guide? Continue exploring our library of 166+ production blueprints, multi-agent swarms, and autonomous agent systems with 100% unblurred, executable source code.