Import std.data.json
JsonReader
class
Public Class JsonReader
Reads a JSON document's tokens, one each time Next is called, from text or from UTF-8 bytes, which it copies: an object's as BEGIN_OBJECT, then each KEY and its value, then END_OBJECT, and an array's as BEGIN_ARRAY, its values, and END_ARRAY. A byte order mark before the JSON is left out. It reads arrays and objects nested in each other up to depth deep.
Examples
Local reader = JsonReader(r"[1, 2, 3]")
Local sum: Int64 = 0
Local token = Try reader.Next()
While token != JsonToken.END
If token == JsonToken.INT Then sum += reader.GetInt64()
token = Try reader.Next()
End While
Expect(sum == 6)-
A JsonReader of
text, which nests up todepthdeep. Panics unlessdepthis 1 or more. -
A JsonReader of
bytes, UTF-8 JSON, which nests up todepthdeep. -
The next token, END once the document's value is done, and END again after. Throws a ParseError where the text stops being JSON, with its line and column, each from 1: of SYNTAX for what can't be there, UNEXPECTED_END for text that ends early, and OUT_OF_RANGE for a number past a Double's range, or arrays and objects nested too deep.
-
The token Next gave last.
-
How many arrays and objects are open after the token: 0 for a document's lone value, 1 after its BEGIN_ARRAY or BEGIN_OBJECT and for each value in it, and 0 again after its END_ARRAY or END_OBJECT.
-
The line, from 1, where the token starts.
-
The column, from 1, in code points, where the token starts.
-
A KEY's or a STRING's text. Panics for another token.
-
An INT's integer. Panics for another token.
-
A UINT's integer, or an INT's that isn't negative. Panics for another token.
-
A number as a Double: a DOUBLE's, or the nearest to an INT's or UINT's. Panics for another token.
-
A BOOL token's value. Panics for another token.
-
Reads past the value whose first token Next gave last, to its END_OBJECT or END_ARRAY when it's an object or an array. Throws as Next does.
Report an issue with this page or with FutureBlitz on GitHub.