Search code examples
jmespath

How to convert list to stream with JMESPath?


Consider this Json:

[
    {
        "Path": "/abc"
    },
    {
        "Path": "/"
    }
]

Using jq the list can be converted to a stream of json documents using .[]

{
"Path": "/abc"
}
{
"Path": "/"
}

What's the way to do this with JMESPath?


Solution

  • JMESPath has no concept of streams as they exist in jq. The output of a JMESPath search is always a single JSON entity. That entity can be an array, of course, but since you already have an array I assume that's not what you want.

    Some – but not all – of the things that you can do with jq streams can be done with the flatten operator [], the multi-select operator [*] and the map(&expr, arr) function, but each problem will need to be tackled differently.