gitmyhub

JsonPath

Java ★ 9.4k updated 3mo ago

Java JsonPath implementation

Jayway JsonPath is a Java library that lets you extract specific values from JSON documents using short path expressions, similar to how XPath works for XML, without writing custom parsing loops.

JavaMavensetup: easycomplexity 2/5

Jayway JsonPath is a Java library that lets developers read and query data out of JSON documents using a path expression syntax. JSON is a common text format used to exchange data between systems, and JsonPath gives you a way to point at specific parts of a JSON document without writing loops or custom parsing code. The concept is similar to how XPath works for XML documents: you write a short expression that describes where the data lives, and the library fetches it.

Path expressions start with a dollar sign representing the root of the document, then navigate down using dot notation or bracket notation. For example, to get the title of the first book in a list, you would write something like $.store.book[0].title. The library also supports wildcards to grab all items in a collection, deep scans to search through nested objects, array slicing, and filter expressions that select items matching a condition, such as all books costing less than a certain price.

Several built-in functions are available at the end of a path expression, covering common operations like finding the minimum, maximum, average, or sum of a set of numbers, getting the length of an array, or retrieving the first or last element. You can also apply filter operators that compare values, check membership in a list, test against a regular expression, or check whether a field is empty.

The library is available through Maven Central, the standard repository for Java dependencies, by adding a few lines to a project's build file. Version 3.0.0 requires Java 17 or newer. Support questions are handled on Stack Overflow using the jsonpath and java tags.

This is a port of the original JsonPath specification created by Stefan Goessner, adapted for use in Java applications.

Where it fits