I have the following input:
{
"data": [
{
"ID": 1,
"TYPE": "A"
}
]
}
And the following Jolt transform:
[
{
"operation": "shift",
"spec": {
"data": {
"*": {
"ID": "[&1].id",
"TYPE": "[&1].type"
}
}
}
}
]
It works fine, and returns:
[
{
"id": 1,
"type": "A"
}
]
However when provided:
{
"data": []
}
It returns null
but I want it to return an empty array, like so:
[]
Is there any way to achieve this?
I have the following input:
{
"data": [
{
"ID": 1,
"TYPE": "A"
}
]
}
And the following Jolt transform:
[
{
"operation": "shift",
"spec": {
"data": {
"*": {
"ID": "[&1].id",
"TYPE": "[&1].type"
}
}
}
}
]
It works fine, and returns:
[
{
"id": 1,
"type": "A"
}
]
However when provided:
{
"data": []
}
It returns null
but I want it to return an empty array, like so:
[]
Is there any way to achieve this?
Share Improve this question edited Nov 20, 2024 at 20:47 Barbaros Özhan 65.4k11 gold badges36 silver badges61 bronze badges asked Nov 20, 2024 at 20:31 Illay Ben NounIllay Ben Noun 112 bronze badges1 Answer
Reset to default 0If it would suffice to get
[
{
"ID": 1,
"TYPE": "A"
}
]
then the following single spec would handle your problem :
[
{
"operation": "shift",
"spec": {
"data": ""
}
}
]
but for your case you can convert it to the following :
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": {
"id": "=(@(1,ID))",
"type": "=(@(1,TYPE))"
}
}
}
},
{
"operation": "remove",
"spec": {
"*": {
"*": {
"ID|TYPE": ""
}
}
}
},
{
"operation": "shift",
"spec": {
"data": ""
}
}
]
third operation of which is the identical with the previously suggested one.