I'm trying to write a script that filters a JSON array by if the objects have a key, "parent_json".
Here's the jolt script I wrote:
[
{
"operation": "shift",
"spec": {
"*": {
"parent_info": {
"": null,
"*": {
"@2": "[]"
}
}
}
}
}
]
And it works beautifully, with the caveat that it is duplicating the matched rows. Take this input JSON:
[
{
"ID": 5,
"username": "test1",
"parent_info": {
"parent_id": 4,
"parent_username": "test"
}
},
{
"ID": 4,
"username": "test"
},
{
"ID": 3,
"username": "admin1",
"parent_info": {
"parent_id": 2,
"parent_username": "admin"
}
},
{
"ID": 2,
"username": "admin"
}
]
And this output JSON:
[
{
"ID": 5,
"username": "test1",
"parent_info": {
"parent_id": 4,
"parent_username": "test"
}
},
{
"ID": 5,
"username": "test1",
"parent_info": {
"parent_id": 4,
"parent_username": "test"
}
},
{
"ID": 3,
"username": "admin1",
"parent_info": {
"parent_id": 2,
"parent_username": "admin"
}
},
{
"ID": 3,
"username": "admin1",
"parent_info": {
"parent_id": 2,
"parent_username": "admin"
}
}
]
Any ideas how I can change the script to not duplicate the output?
