JMESPath是否有条件if / then / else?

问题描述

我正在尝试使用JMESPath做一个简单的if / then / else

例如:“如果输入为字符串,则返回字符串,否则返回输入的“值”属性”。输入"abc"将返回"abc"。输入{"value":"def"}将返回"def"

有了jq,这很容易:if .|type == "string" then . else .value end

使用JMESPath,我可以获取类型

type(@)

或输入:

@

value属性

value

但是我还没有找到一种将它们组合成if-then-else的方法。有什么办法吗?

解决方法

people[?general.id !={ "people": [ { "general": { "id": 100,"age": 20,"other": "foo","name": "Bob" },"history": { "first_login": "2014-01-01","last_login": "2014-01-02" } },{ "general": { "id": 101,"age": 30,"other": "bar","name": "Bill" },"history": { "first_login": "2014-05-01","last_login": "2014-05-02" } } ] } ] ||人

{{1}}

if else 条件在这里有效