KB:Json Path Query

Jason root = $

$.element.

if you have "jq" installed you can use the -c 'path'  to see compacted list of all the elements. 



the $ symbol is often used to represent the root element in JSON data when using tools or languages that support JSONPath, which is a query language for JSON data similar to XPath for XML. Here's why and how it's used:

Why Use $ in JSONPath?

  • Root Reference: The $ symbol in JSONPath represents the root object or array. It's a way to anchor your query to the very beginning of the JSON structure.
  • Navigation: From the $ root, you can navigate through the JSON structure to access nested elements or values by specifying keys or indices.

 




FunctionDescriptionExampleResult
textthe plain textkind is {.kind}kind is List
@the current object{@}the same as input
. or []child operator{.kind}{['kind']} or {['name\.type']}List
..recursive descent{..name}127.0.0.1 127.0.0.2 myself e2e
*wildcard. Get all objects{.items[*].metadata.name}[127.0.0.1 127.0.0.2]
[start:end:step]subscript operator{.users[0].name}myself
[,]union operator{.items[*]['metadata.name', 'status.capacity']}127.0.0.1 127.0.0.2 map[cpu:4] map[cpu:8]
?()filter{.users[?(@.name=="e2e")].user.password}secret
rangeenditerate list{range .items[*]}[{.metadata.name}, {.status.capacity}] {end}[127.0.0.1, map[cpu:4]] [127.0.0.2, map[cpu:8]]
''quote interpreted string{range .items[*]}{.metadata.name}{'\t'}{end}127.0.0.1 127.0.0.2
\escape termination character


Reference:

- https://kubernetes.io/docs/reference/kubectl/jsonpath/


Comments

Popular posts from this blog

KB: Azure ACA Container fails to start (no User Assigned or Delegated Managed Identity found for specified ClientId)

Electron Process Execution Failure with FSLogix

KB:RMM VS DEX (Remote Monitoring Management vs Digital Employee Experience)