Parse functionv0.1.0
pub func Parse(
allocator: Allocator,
input: char8[..]
) -> JsonValue ! JsonParseError
The default limits apply. A failure gives back the reason and its position and no value at all, so a document
that is not a document cannot be mistaken for one that is — which the old shape allowed, since it answered a
refused parse with null, and null is a document.
Fails with any case of JsonParseError, positioned at the byte where parsing stopped.
Parameters
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the value is built |
input | char8[..] | the document, as UTF-8 bytes |
Returns: the document, or the failure that stopped it
Related
DuplicateKeyPolicy
pub enum DuplicateKeyPolicy: int32 {
Reject = 0,
KeepFirst = 1,
KeepLast = 2,
KeepAll = 3
}
What to do about an object containing the same name twice.
Cases
| Name | Value | Description |
|---|---|---|
Reject | 0 | Refuse the document. The default, and the only policy that cannot be used to make two readers disagree. |
KeepFirst | 1 | Keep the first occurrence and discard the rest. |
KeepLast | 2 | Keep the last occurrence, which is what most JavaScript-derived parsers do. |
KeepAll | 3 | Keep every occurrence, in order. The document is preserved exactly, and lookup finds the first. |
ParseWith
pub func ParseWith(
allocator: Allocator,
input: char8[..],
limits: JsonLimits,
duplicates: DuplicateKeyPolicy
) -> JsonValue ! JsonParseError
Parses input under chosen limits and a chosen duplicate-name policy.
The long form of Parse, for a caller who needs something other than the defaults. The policy is a
parameter rather than a mutable setting on a shared parser, so two documents read under different policies
in the same program cannot influence one another.
Fails with any case of JsonParseError, positioned at the byte where parsing stopped. A limit that the document
exceeds arrives as TooDeep or TooManyEntries from the parser, or nested inside Lexical when it was the
lexer that measured it.
Parameters
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the value is built |
input | char8[..] | the document, as UTF-8 bytes |
limits | JsonLimits | what to accept |
duplicates | DuplicateKeyPolicy | what to do about an object naming the same member twice |
Returns: the document, or the failure that stopped it