Introduction


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


As XPath allows us to traverse and fetch information from the XML Document, JSONPath expression allows us to do the same for JSON Documents. Due to the huge popularity of JavaScript language, JSON is one of the most widely used Data Storage format on the Web and this in turn increases the utility of JSONPath.


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.


Syntax


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

A simple guide on JSONPath from Restfulapi.net


And here's an online JSONPath evaluator: JSONPath Online evaluator



Happy Test Automation!