JSONPath: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 18: Line 18:
====<tt>$</tt>====
====<tt>$</tt>====


 
[[#.24|$]] represents the [[JSON_Concepts#Top-Level_Element|top-level element]] (or root) of the JSON document. The "$" is optional, the following are equivalent:
<syntaxhighlight lang='json'>
$.metadata
.metadata
metadata
<syntaxhighlight lang='json'>


There are two ways to select a specific child element relative to the parent element: [[#.property|.''property'']] and [[#.5B0-based-index.5D|[''0-based-index'']]]. These two different syntaxes are applied to JSON [[JSON_Concepts#Objects|Objects]] and [[JSON_Concepts#Arrays|Arrays]], given the fact that JSON has only these two types of collections.
There are two ways to select a specific child element relative to the parent element: [[#.property|.''property'']] and [[#.5B0-based-index.5D|[''0-based-index'']]]. These two different syntaxes are applied to JSON [[JSON_Concepts#Objects|Objects]] and [[JSON_Concepts#Arrays|Arrays]], given the fact that JSON has only these two types of collections.

Revision as of 00:07, 16 March 2021

External

Internal

Overview

JSONPath is a query language for JSON similar to XPath for XML. Some documentation describes it as a Java DSL for reading JSON documents, probably to address those cases where the implementation is made in Java.

Concepts

JSONPath Expression

A JSONPath expression specifies a path to an element or a set of elements that are part of a JSON document. An expression can be assembled using a series of syntax elements presented below.

$

$ represents the top-level element (or root) of the JSON document. The "$" is optional, the following are equivalent:

$.metadata
.metadata
metadata
<syntaxhighlight lang='json'>

There are two ways to select a specific child element relative to the parent element: [[#.property|.''property'']] and [[#.5B0-based-index.5D|[''0-based-index'']]]. These two different syntaxes are applied to JSON [[JSON_Concepts#Objects|Objects]] and [[JSON_Concepts#Arrays|Arrays]], given the fact that JSON has only these two types of collections.

====<tt>.''property''</tt>====
This is called "the dot notation" where a property of the parent JSON [[JSON_Concepts#Objects|Object]] is specified following a dot.
<syntaxhighlight lang='json'>
.metadata.resourceVersion

[0-based-index]

JSONPath Template