JavaScript theorytheory 0/50 · 0%
Data · easy

16. JSON

Serialising, parsing and the BigInt problem.

`JSON.stringify` and `JSON.parse` convert between objects and text. JSON has no BigInt, no undefined and no functions, so wei values must be converted to strings before sending them anywhere.

JSON.stringify({ value: 1n }); // TypeError
JSON.stringify({ value: (1n).toString() }); // {"value":"1"}

JSON-RPC — the protocol every Ethereum node speaks — is exactly this: JSON objects with `method`, `params`, `id` and `jsonrpc`.

Check your understanding

  1. 1. What happens when you stringify a BigInt?

  2. 2. Which JS value disappears in stringify?

  3. 3. What shape does a JSON-RPC request take?