Extract fields by partial name( property value data extraction by calling short name)

 I have a json with attribute names that start with some prefixes I need to ignore, and end with the actual field name:

{
    "context": {
        "values": {
            "group1:0:foo": "08119037",
            "group1:0:checkbox": [
                "2",
                "3"
            ]
        }
    }
}

I can extract the exact field group1:0:foo, but not "the field that ends with :foo":

{
    "foo": context.values.`group1:0:foo`
}

https://try.jsonata.org/9vruWw6HR



{
"context": {
"values": {
"group1:0:foo": "08119037"
}
}
}
method1:
$spread(context.values)[$match($keys($)[0], /.*:foo/)] {
$keys($)[0].$split(":")[2]: $.*
}
method2:
{
"foo": $lookup(context.values, context.values.$keys()[$contains($, 'foo')])
}

No comments:

Post a Comment

calling outside object property or parent

 https://try.jsonata.org/dxPC5s-zM { "list1" : [ { "b" : 1 , "list2" : [ { ...