Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 16420

JOLT SPEC: Shift into existing array

$
0
0

Currently I have the following INPUT JSON.The "temp"-Object has been addedwith the help of a default spec.

{"items" : [ {"description" : "myDescription","attributes" : [ {"identifier" : "colour","type" : "attribute","values" : [ "DE" ],"hint" : "1"    }, {"identifier" : "pin","type" : "attribute","values" : [ "4711" ],"hint" : "1"    }, {"identifier" : "price","type" : "price","values" : [ "77.27" ],"hint" : "1"    }, {"identifier" : "weight","type" : "attribute","values" : [ "0.47" ],"hint" : "1"    }, {"identifier" : "status","type" : "attribute","values" : [ "active" ],"hint" : "1"    } ]  } ],"temp" : {"hint" : "1","identifier" : "additionalDescription","values" : [ {"lang" : "de","value" : "temp"    }, {"lang" : "en","value" : "temp"    }, {"lang" : "fr","value" : "temp"    }, {"lang" : "it","value" : "temp"    }, {"lang" : "es","value" : "temp"    } ],"type" : "attribute"  }}

Desired Output:

{"items" : [ {"description" : "myDescription","attributes" : [ {"identifier" : "colour","type" : "attribute","values" : [ "DE" ],"hint" : "1"    }, {"identifier" : "pin","type" : "attribute","values" : [ "4711" ],"hint" : "1"    }, {"identifier" : "price","type" : "price","values" : [ "77.27" ],"hint" : "1"    }, {"identifier" : "weight","type" : "attribute","values" : [ "0.47" ],"hint" : "1"    }, {"identifier" : "status","type" : "attribute","values" : [ "active" ],"hint" : "1"    }, {"hint" : "1","identifier" : "additionalDescription","values" : [ {"lang" : "de","value" : "myDescription"    }, {"lang" : "en","value" : "myDescription"    }, {"lang" : "fr","value" : "myDescription"    }, {"lang" : "it","value" : "myDescription"    }, {"lang" : "es","value" : "myDescription"    } ],"type" : "attribute"  } ]  } ]}

The spec that I am looking for should fullfill tworequirements:

  1. integrate the "new" object within the attributes array.
  2. replace the value "temp" by the value of the description field,which can be found at the top of the json.

Unfortunately I already struggle with getting the arrays correctly into the output json,not to mention the Overwriting of the value "temp"

[  {"operation": "shift","spec": {"items": {"*": {"description": "&2.myDescription","attributes": {"@(3,temp)": "&3.&2.&","*": "&3.&2.&"          }        }      }    }  }]

Any help are highly appreciated. Also, I would be happy to receive hints regarding the first requirement as well. I always struggle when building the RHS (right-hand side) whenever arrays are involved.


Viewing all articles
Browse latest Browse all 16420

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>