Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Parsing a sequence of JSON values that are not enclosed in a JSON array - https://github.com/leadpony/joy/issues/14
import jakarta.json.Json;
import jakarta.json.JsonValue;
import jakarta.json.stream.JsonParser;
import org.junit.jupiter.api.Test;
import java.io.StringReader;
public class DoesWhatTheJavadocSaysTest {
@Test
void canBeUsedToParseSequenceOfJSONValuesThatAreNotEnclosedInAJSONArray() {
/*
JsonParser can be used to parse sequence of JSON values that are not enclosed in a JSON array, e.g. { } { }. The following code demonstrates how to parse such sequence.
JsonParser parser = Json.createParser(...);
while (parser.hasNext) {
parser.next(); // advance parser state
JsonValue value = parser.getValue();
}
https://eclipse-ee4j.github.io/jsonp/docs/api/jakarta.json/jakarta/json/stream/JsonParser.html
*/
JsonParser parser = Json.createParser(new StringReader("{ } { }"));
while (parser.hasNext()) {
parser.next(); // advance parser state
JsonValue value = parser.getValue();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment