{"id":255,"date":"2018-04-30T16:51:42","date_gmt":"2018-04-30T16:51:42","guid":{"rendered":"https:\/\/restfulapi.net\/?p=255"},"modified":"2021-09-27T23:13:45","modified_gmt":"2021-09-27T17:43:45","slug":"json-syntax","status":"publish","type":"post","link":"https:\/\/restfulapi.net\/json-syntax\/","title":{"rendered":"JSON Syntax"},"content":{"rendered":"\n
A JSON document may contain information separated by the following separators or tokens.<\/p>\n\n\n\n
\":\"<\/code> to separate name from value<\/li>\",\"<\/code> to separate name-value pairs<\/li>\"{\"<\/code> and \"}\"<\/code> for objects<\/li>\"[\"<\/code> and \"]\"<\/code> for arrays<\/li><\/ol>\n\n\n\n1. JSON name-value pairs example<\/h2>\n\n\n\n
Name-value pairs have a colon between them as in \"name\" : \"value\"<\/code>.<\/p>\n\n\n\nJSON names are on the left side of the colon. They need to be wrapped in double quotation marks, as in “name” and can be any valid string. Within each object, keys need to be unique.<\/em><\/p>\n\n\n\nJSON values are found to the right of the colon. At the granular level, these need to be one of 6 simple data types:<\/p>\n\n\n\n
- string<\/li>
- number<\/li>
- object<\/li>
- array<\/li>
- boolean<\/li>
- null or empty<\/li><\/ol>\n\n\n\n
Each name-value pair is separated by a comma, so the JSON looks like this:<\/p>\n\n\n\n
\"name\" : \"value\", \"name\" : \"value\", \"name\": \"value\"<\/code> <\/p>\n\n\n\ne.g.<\/p>\n\n\n\n
{\r\n \"color\" : \"Purple\",\r\n \"id\" : \"210\"\r\n}<\/code><\/pre>\n\n\n\n2. JSON object example<\/h2>\n\n\n\n
A JSON object is a key-value data format that is typically rendered in curly braces. A JSON object looks something like this:<\/p>\n\n\n\n
{\r\n\t\"color\" : \"Purple\",\r\n\t\"id\" : \"210\",\r\n\t\"composition\" : {\r\n\t\t\"R\" : 70,\r\n\t\t\"G\" : 39,\r\n\t\t\"B\" : 89\r\n\t}\r\n}<\/code><\/pre>\n\n\n\n3. JSON array example<\/h2>\n\n\n\n
Data can also be nested within the JSON by using JavaScript arrays that are passed as a value using square brackets [ ]<\/code> on either end of its array type.<\/p>\n\n\n\nJSON arrays are ordered collections and can contain values of different data types.<\/p>\n\n\n\n
{\r\n\t\"colors\" :\r\n\t[\r\n\t\t{\r\n\t\t\"color\" : \"Purple\",\r\n\t\t\"id\" : \"210\"\r\n\t\t},\r\n\t\t{\r\n\t\t\"color\" : \"Blue\",\r\n\t\t\"id\" : \"211\"\r\n\t\t},\r\n\t\t{\r\n\t\t\"color\" : \"Black\",\r\n\t\t\"id\" : \"212\"\r\n\t\t}\r\n\t]\r\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"A JSON document may contain information separated by the following separators or tokens. “:” to separate name from value “,” to separate name-value pairs “{” and “}” for objects “[” and “]” for arrays 1. JSON name-value pairs example Name-value pairs have a colon between them as in “name” : “value”. JSON names are on … Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":249,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[17],"_links":{"self":[{"href":"https:\/\/restfulapi.net\/wp-json\/wp\/v2\/posts\/255"}],"collection":[{"href":"https:\/\/restfulapi.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/restfulapi.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/restfulapi.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/restfulapi.net\/wp-json\/wp\/v2\/comments?post=255"}],"version-history":[{"count":0,"href":"https:\/\/restfulapi.net\/wp-json\/wp\/v2\/posts\/255\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/restfulapi.net\/wp-json\/wp\/v2\/media\/249"}],"wp:attachment":[{"href":"https:\/\/restfulapi.net\/wp-json\/wp\/v2\/media?parent=255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/restfulapi.net\/wp-json\/wp\/v2\/categories?post=255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/restfulapi.net\/wp-json\/wp\/v2\/tags?post=255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}