I was wondering if I can use jolt to add property on a a nested array object by looking at the parent array object
For example, here is the input.json and I want to add a element called as ownerName in the pet object by looking at the parent owners array object.
Input.json
{
"owners": [
{
"name": "John",
"ownerId": 1,
"children": [
{
"name": "Jack",
"childId": 11,
"pets": [
{
"type": "dog",
"ownerId": 2
},
{
"type": "cat",
"ownerId": 2
},
{
"type": "dog",
"ownerId": 1
}
]
},
{
"name": "Jill",
"childId": 12,
"pets": [
{
"type": "dog",
"ownerId": 1
},
{
"type": "cat",
"ownerId": 2
},
{
"type": "dog",
"ownerId": 1
}
]
}
]
},
{
"name": "Jane",
"ownerId": 2,
"children": [
{
"name": "jack",
"childId": 21,
"pets": [
{
"type": "rabbit",
"ownerId": 1
},
{
"type": "dog",
"ownerId": 1
},
{
"type": "cat",
"ownerId": 2
}
]
}
]
}
]
}
expected output
{
"owners": [
{
"name": "John",
"ownerId": 1,
"childs": [
{
"name": "Jack",
"childId": 11,
"pets": [
{
"type": "dog",
"ownerId": 2,
"ownerName": "Jane"
},
{
"type": "cat",
"ownerId": 2,
"ownerName": "Jane"
},
{
"type": "dog",
"ownerId": 1,
"ownerName": "John"
}
]
},
{
"name": "Jill",
"childId": 12,
"pets": [
{
"type": "dog",
"ownerId": 1,
"ownerName": "John"
},
{
"type": "cat",
"ownerId": 2,
"ownerName": "Jane"
},
{
"type": "dog",
"ownerId": 1,
"ownerName": "John"
}
]
}
]
},
{
"name": "Jane",
"ownerId": 2,
"childs": [
{
"name": "jack",
"childId": 21,
"pets": [
{
"type": "rabbit",
"ownerId": 1,
"ownerName": "John"
},
{
"type": "dog",
"ownerId": 1,
"ownerName": "John"
},
{
"type": "cat",
"ownerId": 2,
"ownerName": "Jane"
}
]
}
]
}
]
}
Can I write Jolt spec for this?