bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.56k stars 329 forks source link

Cardinality - convert to ONE if Array is having single json node/Child #1101

Open syamala102 opened 3 years ago

syamala102 commented 3 years ago

Hi Team, Want to know if there is any possibility in JOLT, to check in the existing json array, if single json child exists, then convert it to ONE or else keep it as it is. Can someone please help on this.

Input: { "meta" : { }, "data" : [ { // data is an array having single json node "attributes" : { "test" : "2021-10-21T12:47:05.603+02:00" }, "id" : "1018512922", "type" : "REST" } ] } Output: { "meta" : { }, "data" : { // Array need to be converted to ONE "attributes" : { "test" : "2021-10-21T12:47:05.603+02:00" }, "id" : "1018512922", "type" : "REST" } }

Thankful to jolt team for doing this project, which saved me lot of time.

avx99 commented 2 years ago
[
  {
    "operation": "cardinality",
    "spec": {
      "data" : "ONE"
    }
  }
]