0

I have a json that looks like the following (greatly simplified):

[
    {
        "kind": "vehicles",
        "examples": ["car", "helicopter"]
    },
    {
        "kind": "stars",
        "examples": ["blue", "red", "neutron"]
    }
]

I'd like the transform into another list of dictionaries with the same keys, but the examples list flattened.
So that it looks like:

[
    {
        "kind": "vehicle",
        "example": "car"
    },
    {
        "kind": "vehicle",
        "example": "helicopter"
    },
    {
        "kind": "stars",
        "example": "blue"
    },
    {
        kind: "stars",
        example: "red"
    },
    {
        "kind": "stars",
        "example": "neutron"
    }
]

I am using Python's JMESPath library.
Is this possible using JMESPath?
If so, how?

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
a693673
  • 57
  • 1
  • 1
  • 5
  • 1
    No, this is not possible for the moment being, see the owner answer here, https://stackoverflow.com/questions/28673747/reference-parent-element-in-jmespath-filter-expression. Quoting it: "_We would need to have some mechanism that allows you to bind scope, which is something that is not currently possible...yet. I'm very interested in adding this. For now you'll have to use an alternate tool._". – β.εηοιτ.βε Apr 20 '23 at 17:38
  • Thanks for the answer. I thought this might be the case. – a693673 Apr 20 '23 at 17:56

0 Answers0