

On line 7 we catch JauntException, which is the superclass of all other Jaunt-related Exceptions. The response object contains metadata related to the HTTP response, including header information (see the class HttpResponse for accessing specific headers, etc).

On line 5, the response object is printed. The UserAgent method getSource() can be called to access the original/unaltered JSON.

Malformed JSON is automatically corrected by the parser, so the printed output may not be identical to the original/unparsed data. When the userAgent sends the request (line 3), it creates a JNode ( userAgent.json) to represent the root node of the JSON object in the response. This example illustrates creating a UserAgent, sending a GET request, and printing the JSON response. Include the jar file in your classpath/project, at which point you will be able to recompile and/or run the example files.
Json query exampes zip file#
The zip file contains the licensing agreement, javadocs documentation, example files, release notes, and a jar file (Java 1.6).
Json query exampes download#
To begin using Jaunt, download and extract the zip file. When/if the parser encounters dirty JSON, it attempts to correct the data and is guaranteed to create a parse tree. Queries resemble the JSON object that they are intended to match (see Examples 8 and 9). The class JNode provides intuitive and powerful search methods for finding nodes. As you can see, when working with a JNode, it's important to be cognizant of its type. Finally, The "inStock" child is a JNode (of Type.BOOLEAN) that represents the boolean value false. The "author" child is a JNode (of Type.OBJECT) that represents a JSON object, which has two of its own child JNodes, both Strings. The "editions" child is a JNode (of Type.ARRAY) which contains four child JNodes, each of which represents a number. The child node named "title" is a JNode of Type.STRING that represents the String "The Big Book of Inventions". It is a parent to four child JNodes, each associated with a name ("title", "editions", "author"). In the book example, the root JNode is of Type.OBJECT. Every JNode has a type, which tells whether the JNode represent an object, array, or one of the primitive types (see JNode.getType(), which returns either Type.ARRAY, Type.OBJECT, Type.NUMBER, etc). To represent each of these, the class JNode is used ("JSON Node"). Unlike primitives, objects and arrays can contain other objects/arrays/primitives. This JSON is a tree structure composed of objects, arrays, and primitives (Strings, booleans, numerics). The UserAgent is capabable parsing and querying JSON, allowing it to interact with REST-ful applications. The Jaunt package contains the the class UserAgent, which represents a headless browser.
