O'Reilly logo

Advanced Java® EE Development with WildFly® by Deepak Vohra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing JSON

In this section, we will parse the jsonOutput.txt file generated in the previous section. The JsonParser interface is provided to parse JSON in a streaming way. Create JsonParser using the static method createParser() from the Json class, as follows:

JsonParser parser=Json.createParser(new FileInputStream(new File("C:/json/jsonOutput.txt")));

An alternative to creating a JsonParser object is using a JsonParserFactory factory, which can be created using the static method createParserFactory(), as shown in the following lines of code:

JsonParserFactory factory = Json.createParserFactory(null);
JsonParser parser = factory.createParser(new FileInputStream(new File("C:/json/jsonOutput.txt")));

A JsonParser object can be used to parse a JSON ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required