Unable to transform a JSON Object into Array of objects using JOLT JSON library -


input json have transform follows :

{   "business": [     {       "label": "entertainment",       "category": "advert",       "weight": "",       "types": [         "t1",         "t2"       ]     },     {       "label": "fmcg",       "category": "campaign",       "weight": "",       "types": [         "t9",         "t10"       ]     }   ] } 

expected output :

{   "business": [     {       "label": "entertainment",       "category": "advert",       "weight": "",       "types": "t1"     },     {       "label": "entertainment",       "category": "advert",       "weight": "",       "types": "t2"     },     {       "label": "fmcg",       "category": "campaign",       "weight": "",       "types": "t9"     },     {       "label": "fmcg",       "category": "campaign",       "weight": "",       "types": "t10"     }   ] } 

i have tried different jsonspecs provided @ jolt github page. not able solve this. or pointers appreciated.

you have 2 shift operations.

you want "duplicate" label , category based on how many entries have in "types" array. first, temporary "bizarray".

also record "type" goes duplicated label , category in temporary "typearray", has same indexes bizarray.

in second shift, "join" 2 parallel arrays, "bizarray" , "typesarray" final array.

spec

[   {     "operation": "shift",     "spec": {       "business": {         "*": { // business array           "types": {             "*": { // type array               "@2": "bizarray[]",  // make copy of whole biz object               "@": "typesarray[]"             }           }         }       }     }   },   {     "operation": "shift",     "spec": {       "bizarray": {         "*": { // bizarray index           "label": "business[&1].label",           "category": "business[&1].category",           "weight": "business[&1].weight"         }       },       "typesarray": {         "*": "business[&].types"       }     }   } ] 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -