Need to change JSON response

Hello Community,

I want to 9know how can I get below JSON response

{
“pvProjectID”: “2427827wj”,
“p6ActivityList”: [
{
“pvPprojectID”: “smhcvxsn,x”,
“pvActivityId”: “mxcxzvcb”,
“imo_Vorgangskategorie”: null,
“okz_Komponentenstruktur”: “01”,
“imo_Prozessnummer_Code”: “.Jnxbz1”,
“imo_ZugNummer”: “0m,xzn7”,
“imo_WagenNummer”: “Z”,
“activityName”: “xzb IT”,
“plannedFinishDate”: “2029-02-14T17:00:00.000”,
“blProjectFinish”: “2029-02-14T17:00:00.000”
},
{
“pvActivityId”: “FmzbxzcD”,
“imo_Vorgangskategorie”: null,
“okz_Komponentenstruktur”: “xzbvbzx1”,
“imo_Prozessnummer_Code”: “bxz0”,
“imo_ZugNummer”: “0z7”,
“imo_WagenNummer”: “Z”,
“activityName”: “cxcxzx g”,
“plannedFinishDate”: “2029-03-08T17:00:00.000”,
“blProjectFinish”: “2029-03-08T17:00:00.000”
}
],
“errorText”: “string”
}

Right now I managed to get response in below format

Can some one help me here

Hi @swatifunde,

It would be good if you add the structure of incoming data. It would be easier to help you.

Thanks,
Pero M.

thanks for your response, I don’t have access on source system to change response

Is there anyone who can help me with this ??

@swatifunde - I believe that @pmancevski was simply asking for you to paste the textual response you currently have so we can work towards the format you need. It makes coming up with the expressions easier if you don’t need to try to recreate the original structure.

Sorry for misunderstanding…

Below response what I get from Snaplogic

[
{
“pvPprojectID”:“F363fdfIPP”
“pvActivityId”:“F3swss15AD010O”
“imo_Vorgangskategorie”:null
“okz_Komponentenstruktur”:“R.A.D.01”
“imo_Prozessnummer_Code”:“J.115”
“imo_ZugNummer”:“036”
“imo_WagenNummer”:“Z”
“activityName”:“Durchführung Inbetriebnahme Zugsicherungssystem”
“plannedFinishDate”:“2029-01-04T17:00:00.000”
“blProjectFinish”:“2029-01-04T17:00:00.000”
“test”:“F362fdfdaIBS”
}
{
“pvPprojectID”:“F36sd0IPP”,“pvActivityId”:“F3639C036ZJ131AD010M”,“imo_Vorgangskategorie”:null,“okz_Komponentenstruktur”:“R.A.D.01”,“imo_Prozessnummer_Code”:“J.131”,“imo_ZugNummer”:“036”,“imo_WagenNummer”:“Z”,“activityName”:“Durchführung Inbetriebnahme Train IT”,“plannedFinishDate”:“2028-12-21T17:00:00.000”,“blProjectFinish”:“2028-12-21T17:00:00.000”
}
{
“pvPprojectID”:“Fd00IPP”,“pvActivityId”:“F3639C036ZJ115AD010P”,“imo_Vorgangskategorie”:null,“okz_Komponentenstruktur”:“R.A.D.01”,“imo_Prozessnummer_Code”:“J.115”,“imo_ZugNummer”:“036”,“imo_WagenNummer”:“Z”,“activityName”:“Lauffähigkeitsbescheinigung vor dynamische IBS / dynamische Fahrten”,“plannedFinishDate”:“2029-01-04T17:00:00.000”,“blProjectFinish”:“2029-01-04T17:00:00.000”
}
{
“pvPprojectID”:“F36sd-00IPP”,“pvActivityId”:“F3639dD010N”,“imo_Vorgangskategorie”:null,“okz_Komponentenstruktur”:“R.sdD.01”,“imo_Prozessnummer_Code”:“J.131”,“imo_ZugNummer”:“036”,“imo_WagenNummer”:“Z”,“activityName”:“Durchführung Inbetriebnahme Train IT”,“plannedFinishDate”:“2029-01-11T17:00:00.000”,“blProjectFinish”:“2029-01-11T17:00:00.000”
}
{
“pvPprojectID”:“F3sda00IPP”,“pvActivityId”:“F3639sa85AA__0C”,“imo_Vorgangskategorie”:null,“okz_Komponentenstruktur”:“R.d.A”,“imo_Prozessnummer_Code”:“J.d185”,“imo_ZugNummer”:“036”,“imo_WagenNummer”:“Z”,“activityName”:“Parken”,“plannedFinishDate”:“2029-02-22T17:00:00.000”,“blProjectFinish”:null
}
{
“pvPprojectID”:“F36dc0IPP”,“pvActivityId”:“F3dJ185AA__0A”,“imo_Vorgangskategorie”:null,“okz_Komponentenstruktur”:“R.AaA”,“imo_Prozessnummer_Code”:“Jd185”,“imo_ZugNummer”:“036”,“imo_WagenNummer”:“Z”,“activityName”:“Parken”,“plannedFinishDate”:“2028-12-28T17:00:00.000”,“blProjectFinish”:“2028-12-28T17:00:00.000”
}
{
“pvPprojectID”:“F36dsIPP”,“pvActivityId”:“F363sd104”,“imo_Vorgangskategorie”:null,“okz_Komponentenstruktur”:“R.Asd.01”,“imo_Prozessnummer_Code”:“J.1sa20”,“imo_ZugNummer”:“036”,“imo_WagenNummer”:“Z”,“activityName”:“Betreuung Infrastruktur- / Integrationsprüfungen AM”,“plannedFinishDate”:“2029-01-18T17:00:00.000”,“blProjectFinish”:“2029-01-18T17:00:00.000”
}
{
“pvPprojectID”:“F3d00IPP”,“pvActivityId”:“F3sdD0105”,“imo_Vorgangskategorie”:null,“okz_Komponentenstruktur”:“RsdD.01”,“imo_Prozessnummer_Code”:“J.a120”,“imo_ZugNummer”:“036”,“imo_WagenNummer”:“Z”,“activityName”:“Betreuung Infrastruktur- / Integrationsprüfungen LT”,“plannedFinishDate”:“2029-02-08T17:00:00.000”,“blProjectFinish”:“2029-02-08T17:00:00.000”
}
{
“pvPprojectID”:“F36dIPP”,“pvActivityId”:“F363sd0AD0107”,“imo_Vorgangskategorie”:null,“okz_Komponentenstruktur”:“Rdsa1”,“imo_Prozessnummer_Code”:“J.120”,“imo_ZugNummer”:“036”,“imo_WagenNummer”:“Z”,“activityName”:“Betreuung Infrastruktur- / Integrationsprüfungen AM”,“plannedFinishDate”:“2029-02-14T17:00:00.000”,“blProjectFinish”:“2029-02-14T17:00:00.000”
}
{
“pvPprojectID”:“F36sd-00IPP”,“pvActivityId”:“F36aAD010E”,“imo_Vorgangskategorie”:null,“okz_Komponentenstruktur”:“R.Ad.01”,“imo_Prozessnummer_Code”:“J.090”,“imo_ZugNummer”:“036”,“imo_WagenNummer”:“Z”,“activityName”:“Software / Hardware Hochrüstung nach Einmalprüfung”,“plannedFinishDate”:“2029-03-01T17:00:00.000”,“blProjectFinish”:“2029-03-01T17:00:00.000”
}
]

@swatifunde - I think this example will reformat the response into what you are looking for.
Community 13477 - Restructure JSON_2022_09_26.slp (7.3 KB)

I don’t see where you are getting the pvProjectID value from the provided response data, so I hardcoded that value in the Mapper snap, but I’m guessing you will have that value from either the $original object in the response data, or via pipeline parameter for the pipeline that made the call.

2 Likes

Thanks you so much your response but I am fetching data from Orcale system when I used this logic in my pipeline, I am getting different result

SnapLogic Community below is my pipeline structure

@swatifunde - can you download the output of the data preview from your Oracle select snap as well as the desired output format you are looking for? Upload both of those examples (not screen shots) to this post. I think I’m just getting a bit confused on what the input data to the Mapper looks like and what you want it to output.

@swatifunde - Thanks for following up. Take a look at this updated pipeline.
Community 13477 - Restructure JSON_2022_09_30.slp (11.6 KB)

The main logic to this is the Group By Fields snap that combines the data into a single array around your project id. The first Mapper snap moves the project id out of the $group_by element into the root where you want it. Then the second Mapper snap uses the new $p6ActivityList array as the root where we want make changes and we simply remove the project id from each level. If this syntax seems odd, review the documentation on the Mapper snap, particularly around the Pass Through option.

1 Like

Great, its working as expected. Just small query , is it possible to remove first square bracket from final output?

The surrounding square brackets represent the multiple documents in the data stream - in this case it is only one document but the data stream will always be an array. What is your target? Depending on your endpoint, this is usually correct - since it will output each document per each element of that surrounding array.

Hey @swatifunde,

I presume you exposing this as an api?
If that’s the case, than switch from document to binary output. Map
$ as $content, 200 as $status "application/json" as $['content-type'].

Hope this helps

yes, I am exposing this as an api. but I don’t understand solution here.
If I use Document to binary snap then how can I map this values.

You don’t have to use document to binary. What I meant was change the output of the mapper to binary. You can do that in in the Views tab on the Mapper:

1 Like

ohhh, got it, its done now but what about other statement you mentioned earlier
$ as $content, 200 as $status “application/json” as $[‘content-type’].

Getting below error

1 Like

Check the quotes.

Should be $['Content-Type']

2 Likes