{"id":248,"date":"2018-04-30T10:35:24","date_gmt":"2018-04-30T10:35:24","guid":{"rendered":"https:\/\/restfulapi.net\/?p=248"},"modified":"2021-09-27T23:21:02","modified_gmt":"2021-09-27T17:51:02","slug":"introduction-to-json","status":"publish","type":"post","link":"https:\/\/restfulapi.net\/introduction-to-json\/","title":{"rendered":"What is JSON"},"content":{"rendered":"\n

JSON (JavaScript Object Notation)<\/strong> is the most widely used data format for data interchange<\/strong> on the web. This data interchange can happen between two computer applications at different geographical locations or running within the same machine.<\/p>\n\n\n\n

The good thing is that JSON is a human-readable as well as a machine-readable format. So while applications\/libraries can parse the JSON documents – humans can also look at the data and derive the meaning from it.<\/p>\n\n\n\n

All modern programming languages (e.g., Java, JavaScript, Ruby, C#, PHP, Python, and Groovy) and application platforms provide excellent support for producing (serializing<\/strong>) and consuming (deserializing<\/strong>) JSON data.<\/p>\n\n\n\n

1. JSON Specifications<\/h2>\n\n\n\n

Douglas Crockford originally created JSON in 2001, and initially standardized it in 2006 under RFC 4627<\/a> through the IETF. In 2013, Ecma International also standardized JSON under ECMA 404<\/a>.<\/p>\n\n\n\n

In March 2014, Tim Bray corrected errata with the original IETF 4627 in IETF RFC 7158<\/a> and RFC 7159<\/a>. <\/p>\n\n\n\n

The new specifications remove inconsistencies with other specifications of JSON, repairs specification errors, and offer experience-based interoperability guidance.<\/p>\n\n\n\n

2. JSON File and MIME Type<\/h2>\n\n\n\n

The standard file type for storing a JSON document in the filesystem is .json<\/code>.<\/p>\n\n\n\n

JSON\u2019s Internet Assigned Numbers Authority (IANA) media (or MIME) type is application\/json<\/a><\/code>.<\/p>\n\n\n\n

3. JSON Document<\/h2>\n\n\n\n

A JSON document may contain text, curly braces, square brackets, colons, commas, double quotes, and maybe a few other characters.<\/p>\n\n\n\n

Primarily, a valid JSON document can contain two structures:<\/p>\n\n\n\n

  1. An Object<\/strong> surrounded by curly braces and containing multiple name\/value pairs. In various languages, this is realized as an record, struct, dictionary, hash table, keyed list, or associative array.<\/li>
  2. An Array or Ordered list<\/strong> of values surrounded by square brackets. In most languages, this is realized as an vector, list, or sequence.<\/li><\/ol>\n\n\n\n

    4. JSON Example<\/h2>\n\n\n\n

    An example JSON document is:<\/p>\n\n\n\n

    \/\/JSON Object\r\n\r\n{\r\n\t\"employee\": {\r\n\t\t\"id\": 1,\r\n\t\t\"name\": \"Admin\",\r\n\t\t\"location\": \"USA\"\r\n\t}\r\n}\r\n\r\n\/\/JSON Array\r\n\r\n{\r\n\t\"employees\": [\r\n\t\t{\r\n\t\t\t\"id\": 1,\r\n\t\t\t\"name\": \"Admin\",\r\n\t\t\t\"location\": \"India\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"id\": 2,\r\n\t\t\t\"name\": \"Author\",\r\n\t\t\t\"location\": \"USA\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"id\": 3,\r\n\t\t\t\"name\": \"Visitor\",\r\n\t\t\t\"location\": \"USA\"\r\n\t\t}\r\n\t]\r\n}<\/code><\/pre>\n\n\n\n

    As we can see, the JSON document consists of name\/value pairs. These name\/value pairs reflect the structure of the data.<\/p>\n\n\n\n

    5. Learning JSON<\/h2>\n\n\n\n

    In this JSON tutorial, we will learn the various concepts about JSON, with examples.<\/p>\n\n\n\n