如何仅选择包含具有N个以上元素的数组的对象

时间:2019-02-11 11:47:04

标签: jmespath

仅捕获以下数组中的第二个对象的正确的JMESPath表达式是什么(因为它的topics数组中有两个以上的对象):

[{
  "topics": [
    "just one"
  ]
 },
 {
  "topics": [
    "first",
    "second",
    "third"
  ]
 }
]

我要吐出来

{
  "topics": [
    "first",
    "second",
    "third"
  ]
}

我尝试过[? length(topics) > 2],但jp抱怨:

SyntaxError: Invalid token: tNumber
[? length(topics) > 2]
                    ^

1 个答案:

答案 0 :(得分:0)

输入:

[{
  "topics": [
    "just one"
  ]
 },
 {
  "topics": [
    "first",
    "second",
    "third"
  ]
 }
]

使用jmesExpression:

[?length(topics)>'2']

获取输出:

[
  {
    "topics": [
      "first",
      "second",
      "third"
    ]
  }
]