Expand description
JSON parsing and typed decoding for the OCPI CDR pricing/generating and CDR/Tariff linting pipeline.
§Parsing vs decoding
Parsing and decoding are intentionally separated so the linter can emit actionable warnings rather than hard parse errors.
Parsing (parse_object) converts a raw JSON &str into an
Element tree. The parser is deliberately lenient about string content:
it only verifies structural correctness (balanced delimiters, valid
top-level values) and leaves escape sequences and control characters
untouched inside RawStr.
Decoding (decode) interprets the raw JSON String as a &str.
Calling RawStr::decode_escapes validates escape sequences and
rejects control characters, returning decode::Warning
values instead of hard errors. This lets the linter pinpoint the exact
field, report what is wrong, and suggest a corrected encoding.
The price and generate mods can choose to hard fail on specific Warnings.
Modules§
Structs§
- Components
- Iterator over the
Components of aPath; seePath::components. - Document
- The output of
parse_object: the element tree with path resolution embedded in each element. - ElemId
- Unique sequential index of a JSON
Elementwithin a document. - Element
- A JSON
Elementwith identity, source span, and value. - Error
- A parse error produced when the input is not well-formed JSON.
- Escape
Str - A
&strwith escape chars. - Field
- An object field; upholds the invariant that the inner
Element’s path ends with a key. - Lexical
Issues - The lexical issues a
RawStrmay contain, discovered in a single pass byRawStr::lexical_issues. - Location
- A file location expressed as line and column.
- Path
- The RFC 9535 path locating an
Elementin itsDocument, such as$.charging_periods[0].dimensions. - PathSet
- Set of path with a common issue.
- RawStr
- A
&strwith surrounding quotes removed; escape sequences are not decoded. - Span
- Byte range of a JSON token within the source string.
Enums§
- Component
- A single
Pathcomponent: an object member or an array index. - Parse
Error - Why a raw JSON
&strcould not be turned into aDocument. - Parse
Error Kind - The specific reason a
crate::json::parse_objectcall failed. - Pending
Str - Marks a
&stras having escapes or not. - Removal
Error - Why a set of elements could not be resolved to removal spans.
- Value
- A JSON value that borrows its content from the source JSON
&str. - Value
Kind - Which of the six JSON kinds a
Valueis, without its content.
Functions§
- line_
col - Return the line and column indices of the end of the slice.
- parse_
object - Parse a raw JSON
&strinto aDocumentand require the root value to be a JSON object.