一个json数据的查询语言

Github: https://github.com/jmespath

官网(文档、示例等): https://jmespath.org/


属性

属性1.属性2.属性3.属性4

  • a.b.c
  • a.b.c[0].d[1][0]

数组

[start:stop:step]

  • [1]
  • [0:5]
  • [:5]
  • [::2]

投影 Projections(可理解为map)

分为如下几种投影

  • List Projections
  • Slice Projections
  • Object Projections
  • Flatten Projections
  • Filter Projections

列表投影

示例数据

{
  "people": [
    {"first": "James", "last": "d"},
    {"first": "Jacob", "last": "e"},
    {"first": "Jayden", "last": "f"},
    {"missing": "different"}
  ],
  "foo": {"bar": "baz"}
}

people[*].first

[
  "James",
  "Jacob",
  "Jayden"
]

分割投影

people[:2].first

[
  "James",
  "Jacob"
]

对象投影

ops.*.numArgs

扁平化投影

reservations[*].instances[*].state

过滤投影

machines[?state=='running'].name

管道符投影

people[*].first | [0]


多字段

people[].[name, state.name]

多字段重命名

people[].{Name: name, State: state.name}


函数

length(people)

max_by(people, &age).name

myarray[?contains(@, 'foo') == `true`]