JSON

Specifications

A JSON literal can be one of seven types:

  • null literal
  • true literal
  • false literal
  • numeric literal
  • string literal (delimited by double quotes: " ")
  • array literal (delimited by square brackets with comma separators: [ , ]
  • object literal (delimited by braces with colon and comma separators: { : , }

Because the elements of an array and the values of an object can be any of the seven literals, JSON literals are recursive.

Object keys must be strings.

Dynamic Type Languages

How to de-serialize and serialize JSON.

JavaScript:

let s = '{"t":1,"f":0}';
let data = JSON.parse(s);
let s2 = JSON.stringify(data);

Python:

import json

s = '{"t":1,"f":0}'
data = json.loads(s)
s2 = json.dumps(data)

Ruby:

require 'json'

s = '{"t":1,"f":0}'
data = JSON.parse(s)
s2 = data.to_json

Shell and jq

Databases

Configuration Files

  • YAML

json reference

JSON Data

Static Type Languages

  • go, java, c++
  • IDL

protobuf, thrift, what else?

Numeric Types

integers, fractions, floats

  • javascript integers
  • javascript floating point

Overflow issues integers, floats

Strings

encoding issues

Arrays

ordering issues

Objects

Keys must be strings

Speed and Size Issues

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License