Creates a new JsonReader that reads from the specified ReadableStream.
A ReadableStream containing JSON data as Uint8Array chunks
Closes the reader and releases any resources associated with it.
A Promise that resolves when the reader has been closed
Looks at the next token in the JSON stream without consuming it.
This method allows you to check what type of token is coming next without advancing the reader position.
A Promise that resolves to the type of the next token
Checks if there are more elements in the current array or object.
This method is typically used in a while loop to iterate through all elements in an array or all properties in an object.
A Promise that resolves to true if there are more elements, or false if the end of the current array or object has been reached
Reads the name of the next property in a JSON object.
A Promise that resolves to the name of the property
Reads the next value as a string.
If the next value is already a string, it is returned as is. If the next value is another primitive type, it is converted to a string using JSON.stringify.
A Promise that resolves to the string value
Skips the next value in the JSON stream.
// Skip properties you don't care about
await reader.beginObject();
while (await reader.hasNext()) {
const name = await reader.nextName();
if (name === "importantProperty") {
const value = await reader.nextString();
console.log(value);
} else {
await reader.skipValue(); // Skip this property
}
}
await reader.endObject();
Reads the next complete JSON value (object, array, or primitive).
This method parses and returns the entire next value in the JSON stream, regardless of its complexity. It's useful when you want to read a complete JSON structure without manually navigating through it.
A Promise that resolves to the parsed JSON value
A streaming JSON reader that allows streaming parsing of JSON data.
JsonReader provides methods to navigate through a JSON structure without loading the entire content into memory. This is particularly useful for processing large JSON files or streams efficiently.