Question

I'm sorry if this is really trivial, but I've got a series of data as follows:

{"color":{"red":255,"blue":123,"green",1}}

I know it's in this format because, for some reason, it's easy to work with. What is this format called so that I might look it up?

\edit: If there is any significance to the organization of the data, of course.

Was it helpful?

Solution

That's JSON, a serialised text data storage based on a subset of JavaScript Object Notation. To learn more about JSON, vist: http://json.org

In JSON, there are the following data types:

  • object
  • array
  • number
  • string
  • null
  • boolean

Objects are represented using the following syntax, and are key-value pairings, similar to a dictionary (the key must be a string):

{ "number": 1, "string": "test" }

Like dictionaries, objects are unordered.

An array is a ordered, heterogeneous data structure, represented using the following syntax:

[0, true, false, "1", null]

Numbers are what you'd expect, however unlike JavaScript itself they cannot be Infinity or NaN (i.e. they must be decimals or integers) and contain no leading 0s. Exponents are represented using the following format (the e is not case sensitive):

10e6

where 10 is the base and 6 is the exponent - this is equivalent to 1000000 (1 million). The exponent section may have leading 0s, though there is not much point and may lower compatibility with parsers which are not 100% compliant.

Booleans are case sensitive and are both lowercase. In JSON, there are only two booleans:

true
false

To represent an intentionally left out or otherwise unknown field, use null (case sensitive too).

Strings must be delimited using double quotes (single quotes are invalid syntax), and single quotes need not be escaped.

"This string is valid, and it's alright to do this."
'No, this won't work'
'Nor will this.'

There are numerous escapes available using the backslash character - to use a literal backslash, use \\.

As JSON is a data transmission format, there is no syntax for comments available.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top