The table below is a quick-reference for folks working closely with the Universal Binary JSON format that want all the information at their finger tips:
| Type | Size | Marker | Length | Data Payload |
| [box type=”download” icon=”none”]Value Types[/box] | ||||
| null | 1-byte | Z | No | No |
| no-op | 1-byte | N | No | No |
| true | 1-byte | T | No | No |
| false | 1-byte | F | No | No |
| int8 | 2-bytes | i | No | Yes |
| uint8 | 2-bytes | U | No | Yes |
| int16 | 3-bytes | I | No | Yes |
| int32 | 5-bytes | l | No | Yes |
| int64 | 9-bytes | L | No | Yes |
| float32 | 5-bytes | d | No | Yes |
| float64 | 9-bytes | D | No | Yes |
| high-precision number | 1-byte + int num val + string byte len | H | Yes | Yes (if non-empty) |
| char | 2-bytes | C | No | Yes |
| string | 1-byte + int num val + string byte len | S | Yes | Yes (if non-empty) |
| [box type=”download” icon=”none”]Container Types[/box] | ||||
| array** | 2+ bytes | [ and ] | Optional | Yes (if non-empty) |
| object** | 2+ bytes | { and } | Optional | Yes (if non-empty) |
** See container optimized format for details.
Example
Below is an example of what a common JSON response would look like in UBJSON. This particular example was taken from the GitHub developer docs.
JSON Response
{
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat",
"name": "monalisa octocat",
"company": "GitHub",
"blog": "https://github.com/blog",
"location": "San Francisco",
"email": "octocat@github.com",
"hireable": false,
"bio": "There once was...",
"public_repos": 2,
"public_gists": 1,
"followers": 20,
"following": 0,
"html_url": "https://github.com/octocat",
"created_at": "2008-01-14T04:33:35Z",
"type": "User",
"total_private_repos": 100,
"owned_private_repos": 100,
"private_gists": 81,
"disk_usage": 10000,
"collaborators": 8,
"plan": {
"name": "Medium",
"space": 400,
"collaborators": 10,
"private_repos": 20
}
}
UBJSON Response (using block-notation)
[{]
[i][5][login][S][i][7][octocat]
[i][2][id][i][1]
[i][10][avatar_url][S][i][49][https://github.com/images/error/octocat_happy.gif]
[i][11][gravatar_id][S][i][11][somehexcode]
[i][3][url][S][i][36][https://api.github.com/users/octocat]
[i][4][name][S][i][16][monalisa octocat]
[i][7][company][S][i][6][GitHub]
[i][4][blog][S][i][23][https://github.com/blog]
[i][8][location][S][i][13][San Francisco]
[i][5][email][S][i][18][octocat@github.com]
[i][8][hireable][F]
[i][3][bio][S][i][17][There once was...]
[i][12][public_repos][i][2]
[i][12][public_gists][i][1]
[i][9][followers][i][20]
[i][9][following][i][0]
[i][8][html_url][S][i][26][https://github.com/octocat]
[i][10][created_at][S][i][20][2008-01-14T04:33:35Z]
[i][4][type][S][i][4][User]
[i][19][total_private_repos][i][100]
[i][19][owned_private_repos][i][100]
[i][13][private_gists][i][81]
[i][10][disk_usage][I][10000]
[i][13][collaborators][i][8]
[i][4][plan][{]
[i][4][name][S][i][6][Medium]
[i][5][space][I][400]
[i][13][collaborators][i][10]
[i][13][private_repos][i][20]
[}]
[}]