cancel
Showing results for 
Search instead for 
Did you mean: 

Move objects structure with in json

hasmukhp27
New Contributor

Hello Community Folks,

I've been trying to modify or re-structure the json payload that I'm getting using mapper snap. But I'm finding difficulty achieving it. 

 

Source JSON is --> 

[
  {
    "entity": [
      {
        "id": "6441225a5e40189adb5b7f3d_73114fa2-dcc7-441f-b14f-630742c1da1b",
        "state": "Stopped",
        "create_time": "2023-12-18T18:58:58.134000+00:00",
        "state_timestamp": "2023-12-18T18:59:02.134000+00:00",
        "path_id": "/Example-DEV/projects/User-Example-01",
        "documents": 0,
        "error_documents": 0,
        "label": "Example_11_JMS_Consumer_Example",
        "runtime_label": "ExampleGP",
        "user_id": "user01.email@Example.com",
        "runtime_path_id": "Example-DEV/rt/sidekick/Development",
        "subpipes": {
 
        },
        "invoker": "manual",
        "has_lints": false,
        "child_has_lints": false,
        "duration": 5,
        "mode": "standard",
        "cc_label": "snaplogic-snaplogic-snaplex-jcc-75f756866-ml88n",
        "pipe_id": "0cba7387-e092-40ba-9434-836c19bafcc8",
        "parent_ruuid": null,
        "ccid": "656e1967b14606d6ee6cd31c"
      },
      {
        "id": "6441225a5e40189adb5b7f3d_32e835df-19eb-40bc-b66b-2bc137f82ac0",
        "state": "Stopped",
        "create_time": "2023-12-18T20:21:52.332000+00:00",
        "state_timestamp": "2023-12-18T20:23:14.332000+00:00",
        "path_id": "/Example-DEV/projects/User-Example-01",
        "documents": 0,
        "error_documents": 0,
        "label": "Example_11_JMS_Consumer_Example",
        "runtime_label": "ExampleGP",
        "user_id": "user01.email@Example.com",
        "runtime_path_id": "Example-DEV/rt/sidekick/Development",
        "subpipes": {
 
        },
        "invoker": "manual",
        "has_lints": false,
        "child_has_lints": false,
        "duration": 85,
        "mode": "standard",
        "cc_label": "snaplogic-snaplogic-snaplex-jcc-75f756866-ml88n",
        "pipe_id": "0cba7387-e092-40ba-9434-836c19bafcc8",
        "parent_ruuid": null,
        "ccid": "656e1967b14606d6ee6cd31c"
      },
      {
        "id": "6441225a5e40189adb5b7f3d_6ec57a06-a635-4806-8000-815fbc506c48",
        "state": "Stopped",
        "create_time": "2023-12-18T20:23:41.205000+00:00",
        "state_timestamp": "2023-12-18T20:23:46.205000+00:00",
        "path_id": "/Example-DEV/projects/User-Example-01",
        "documents": 5,
        "error_documents": 0,
        "label": "Example_12_JMS_Subscribe_Topic",
        "runtime_label": "ExampleGP",
        "user_id": "user01.email@Example.com",
        "runtime_path_id": "Example-DEV/rt/sidekick/Development",
        "subpipes": {
 
        },
        "invoker": "manual",
        "has_lints": false,
        "child_has_lints": false,
        "duration": 6,
        "mode": "standard",
        "cc_label": "snaplogic-snaplogic-snaplex-jcc-75f756866-ml88n",
        "pipe_id": "5689d737-0d6f-4fd1-9a97-ddfc2788e848",
        "parent_ruuid": null,
        "ccid": "656e1967b14606d6ee6cd31c"
      }
    ]
  },
  {
    "entity": [
      {
        "id": "5467839a5e40189adb5b7f3d_73114fa2-dcc7-441f-b14f-630742c1da56",
        "state": "Failed",
        "create_time": "2023-12-18T18:58:58.134000+00:00",
        "state_timestamp": "2023-12-18T18:59:02.134000+00:00",
        "path_id": "/Example-DEV/projects/User-Example-01",
        "documents": 0,
        "error_documents": 0,
        "label": "Example_21_JMS_Consumer_Example",
        "runtime_label": "ExampleGP",
        "user_id": "user01.email@Example.com",
        "runtime_path_id": "Example-DEV/rt/sidekick/Development",
        "subpipes": {
 
        },
        "invoker": "manual",
        "has_lints": false,
        "child_has_lints": false,
        "duration": 5,
        "mode": "standard",
        "cc_label": "snaplogic-snaplogic-snaplex-jcc-75f756866-ml88n",
        "pipe_id": "0cba7387-e092-40ba-9434-836c19bafcc8",
        "parent_ruuid": null,
        "ccid": "656e1967b14606d6ee6cd31c"
      },
  {
        "id": "2245673a5e40189adb5b7f3d_73114fa2-dcc7-441f-b14f-630742c1da09",
        "state": "Failed",
        "create_time": "2023-12-18T18:58:58.134000+00:00",
        "state_timestamp": "2023-12-18T18:59:02.134000+00:00",
        "path_id": "/Example-DEV/projects/User-Example-01",
        "documents": 0,
        "error_documents": 0,
        "label": "Example_22_JMS_Consumer_Example",
        "runtime_label": "ExampleGP",
        "user_id": "user01.email@Example.com",
        "runtime_path_id": "Example-DEV/rt/sidekick/Development",
        "subpipes": {
 
        },
        "invoker": "manual",
        "has_lints": false,
        "child_has_lints": false,
        "duration": 5,
        "mode": "standard",
        "cc_label": "snaplogic-snaplogic-snaplex-jcc-75f756866-ml88n",
        "pipe_id": "0cba7387-e092-40ba-9434-836c19bafcc8",
        "parent_ruuid": null,
        "ccid": "656e1967b14606d6ee6cd31c"
      },
    ]
   }
]
 
After applying transformation/mapper, I would ideally like target json to be -->
 
[
{
"pipeline": {
"path_id": "/Example-DEV/projects/User-Example-01",
"label": "Example_11_JMS_Consumer_Example",
"state": "Stopped",
"state_timestamp": "2023-12-18T18:59:02.134000+00:00"
}
},
{
"pipeline": {
"path_id": "/Example-DEV/projects/User-Example-01",
"label": "Example_11_JMS_Consumer_Example",
"state": "Stopped",
"state_timestamp": "2023-12-18T20:23:14.332000+00:00"
}
},
{
"pipeline": {
"path_id": "/Example-DEV/projects/User-Example-01",
"label": "Example_12_JMS_Subscribe_Topic",
"state": "Stopped",
"state_timestamp": "2023-12-18T20:23:46.205000+00:00"
}
},
{
"pipeline": {
"path_id": "/Example-DEV/projects/User-Example-01",
"label": "Example_21_JMS_Consumer_Example",
"state": "Failed",
"state_timestamp": "2023-12-18T18:59:02.134000+00:00"
}
},
{
"pipeline": {
"path_id": "/Example-DEV/projects/User-Example-01",
"label": "Example_22_JMS_Consumer_Example",
"state": "Failed",
"state_timestamp": "2023-12-18T18:59:02.134000+00:00"
}
}
]
 
, I've tried with numerous techniques like javascript map() function on arrays or using jsonPath() and other stuff but nothing seems to work, may be I'm not going on a right path so if someone can please help me here with this providing right path to look around for stuff or even an example of similar stuff will be great. 
 
The JSON that I'm generating is collecting all the "Name" for example in single name value pair if you guys know what I mean.
 
Let me know if you want me to attach something here and show how I'm trying to achieve this.
 
 
1 ACCEPTED SOLUTION

bojanvelevski
Valued Contributor

Hi @hasmukhp27

What you need is a JSONSplitter snap set to split the entity arrays. The rest is easy, the output documents contain the data you need, and you just need to map it accordingly.

bojanvelevski_0-1703085674970.pngbojanvelevski_1-1703085700951.png

 

Regards,

Bojan

View solution in original post

2 REPLIES 2

bojanvelevski
Valued Contributor

Hi @hasmukhp27

What you need is a JSONSplitter snap set to split the entity arrays. The rest is easy, the output documents contain the data you need, and you just need to map it accordingly.

bojanvelevski_0-1703085674970.pngbojanvelevski_1-1703085700951.png

 

Regards,

Bojan

hasmukhp27
New Contributor

Thank you so much @bojanvelevski, you were spot on there. This helped a great deal with an example of the solution as well and I think it's elegant solution as well as it is very clearly outlined and easier to understand.