mirror of
https://github.com/nlohmann/json.git
synced 2026-10-25 15:28:54 +00:00
deploy: 52b72b5684
This commit is contained in:
1 parent
7130ea885a
commit
39c2507b2a
629 files changed
+3665
-1648
No files matched your search
@@ -151,6 +151,36 @@ Output:
|
||||
[$i#i812345678
|
||||
```
|
||||
|
||||
### Byte layout
|
||||
|
||||
Consider the following JSON value (shown formatted for readability):
|
||||
|
||||
```
|
||||
{
|
||||
"id": 300,
|
||||
"name": "json",
|
||||
"pi": 3.14,
|
||||
"tags": [
|
||||
"a",
|
||||
"b"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
`to_ubjson` encodes it to 51 bytes (shown in hexadecimal; the encoding contains no whitespace). The colors mark the role of each byte: type/marker length/count/size data.
|
||||
|
||||
| JSON | Bytes | Meaning |
|
||||
| ----------------- | -------------------------------------- | ----------------------------------------------------------------------------- |
|
||||
| `{` | 7B | object start (`{`) |
|
||||
| `"id": 300,` | 69 02 69 64 49 01 2C | key: length 2 as int8 (`i`), then UTF-8 bytes; value: int16 (`I`), big-endian |
|
||||
| `"name": "json",` | 69 04 6E 61 6D 65 53 69 04 6A 73 6F 6E | key: length 4; value: string (`S`), length 4 as int8, UTF-8 bytes |
|
||||
| `"pi": 3.14,` | 69 02 70 69 44 40 09 1E B8 51 EB 85 1F | key: length 2; value: float64 (`D`), big-endian |
|
||||
| `"tags": [` | 69 04 74 61 67 73 5B | key: length 4; value: array start (`[`) |
|
||||
| `"a",` | 53 69 01 61 | string, length 1 |
|
||||
| `"b"` | 53 69 01 62 | string, length 1 |
|
||||
| `]` | 5D | array end (`]`) |
|
||||
| `}` | 7D | object end (`}`) |
|
||||
|
||||
## Deserialization
|
||||
|
||||
The library maps UBJSON types to JSON value types as follows:
|
||||
|
||||
Reference in new issue
Block a user