The simplest definition would be "JSONPath is to JSON as XPath is to XML".
Please check the following documentation if you are not familiar with JSON - JSON Guide
Following are two of the main advantages of using JSONPath:
- Data may be interactively found and extracted out of JSON structures on the client without special scripting.
- JSON data requested by the client can be reduced to the relevant parts on the server, such minimizing the bandwidth usage of the server response.
A JSONPath expression contains the following symbols:
$– symbol refers to the root object or element.
@– symbol refers to the current object or element.
.– operator is the dot-child operator, which you use to denote a child element of the current element.
[ ]– is the subscript operator, which you use to denote a child element of the current element (by name or index).
*– operator is a wildcard, returning all objects or elements regardless of their names.
,– operator is the union operator, which returns the union of the children or indexes indicated.
:– operator is the array slice operator, so you can slice collections using the syntax
[start:end:step]to return a subcollection of a collection.
( )– operator lets you pass a script expression in the underlying implementation’s script language. It’s not supported by every implementation of JSONPath, however.
? ( )– to query all items that meet a certain criteria.
More details can be found here:
Java port for JSONPath
And here's an online JSONPath evaluator: JSONPath Online evaluator
Happy Test Automation!