Contains functions to parse JSON values, show them for debugging, and extract information from them.
Functions which extract information are rather strict: they don't try to be smart and automatically convert. For instance, as_record makes sure that all fields are taken into account. This is suited to write a tool that must be updated when the format of JSON values being manipulated changes. In our case, if the JSON schemas we read start to get more fields, we want to know; otherwise the resulting OpenAPI specification could be inaccurate.
The origin is a string you give to annotate or parse, such as "RPC response". It denotes where the value comes from. It is used in error messages (see the comment in the Decoding section).
Same as parse, but return None instead of raising Error.
The general pattern for the accessors below is that only as_x functions can fail. Getters get and geti return `Null instead of failing. This allows to chain them and only test for errors at the end with as_x, either by raising Error or by returning None (with the as_x_opt variant).
Internally, the actual error which is printed is the correct one. For instance, with json |-> "x" |> as_int, if json is not an object, the call to as_int causes the test to fail with "<origin>: not an object" where <origin> is the ~origin you gave to parse. If json is an object but "x" does not exist, as_int causes the test to fail with "<origin>: missing field: x". If "x" exists but is not an integer, as_int causes the test to fail with "<origin> at .x: expected an integer".
Objects are equal only when they have the exact same number of fields with the same contents (their order does not matter). Consequently, e.g. {"a": 1} is not equal to {"a": 1, "a": 1}.
Arrays are equal when they contain the same number of pair-wise equal elements.