JavaScript JSON

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write and easy for machines to parse and generate. It is important to realize that, in JavaScript, JSON is a string and not an object.

A basic overview can be found on the json.org website which also contains links to implementations of the standard in many different programming languages.

Syntax

  • JSON.parse(input[, reviver])
  • JSON.stringify(value[, replacer[, space]])

Parameters

ParameterDetails
JSON.parseParse a JSON string
input(string)JSON string to be parsed.
reviver(function)Prescribes a transformation for the input JSON string.
JSON.stringifySerialize a serializable value
value(string)Value to be serialized according to the JSON specification.
replacer(function or String[] or Number[])Selectively includes certain properties of the value object.
space(String or Number)If a number is provided, then space number of whitespaces will be inserted of readability. If a string is provided, the string (first 10 characters) will be used as whitespaces.

Remarks

The JSON utility methods were first standardized in ECMAScript 5.1 ยง15.12.

The format was formally defined in The application/json Media Type for JSON (RFC 4627 July 2006) which was later updated in The JSON Data Interchange Format (RFC 7158 March 2013, ECMA-404 October 2013 and RFC 7159 March 2014).

To make these methods available in old browsers such as Internet Explorer 8, use Douglas Crockford's json2.js.



Got any JavaScript Question?