API express change JSON result format

This forum contains topics that were moved from Get Satisfaction
Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

API express change JSON result format

Post by Takis »

Hello

I used API express, I connected to an external MYSQL, OK.
I created the call OK and I get the below response, after executing my SQL query

[{
"MenuName": "Food",
"MenuSubID": 4,
"MenuSubName": "Fast Food"
}, {
"MenuName": "Food",
"MenuSubID": 5,
"MenuSubName": "Mexican"
}, {
"MenuName": "Sport",
"MenuSubID": 3,
"MenuSubName": "Tenis"
}]

through an SQL component

I THEN want to change the format of this JSON result, via Script component (?) to the below

"MenuName": "Food"
"MenuSubID": 4, "MenuSubName": "Fast Food"
"MenuSubID": 5, "MenuSubName": "Mexican"

"MenuName": "Sport"
"MenuSubID": 3 "MenuSubName": "Tenis"

Thanks

Serhii Kulibaba
Posts: 147
Joined: Tue Aug 27, 2013 1:47 pm

API express change JSON result format

Post by Serhii Kulibaba »

Hello,

It is impossible to use parameters with the same name in the only one JSON object

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

API express change JSON result format

Post by Takis »

What I want to do is take the output of the JSON (api express SQL component), change the grouping and then give the final changed JSON response.

Can be done by Mapping component? Image

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

API express change JSON result format

Post by Takis »

The result I want is (simplyfied)

Food
4, Fast Food
5, Mexican

Sport
3, Tenis

So using Mapping component, I would like to group the initial output by MenuName (Food, Sport)

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

API express change JSON result format

Post by Takis »

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

API express change JSON result format

Post by Takis »

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

API express change JSON result format

Post by Takis »

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

API express change JSON result format

Post by Takis »

Or can by done in a Script component?

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

API express change JSON result format

Post by Takis »

Any feedback please. Should have been easy.

Serhii Kulibaba
Posts: 147
Joined: Tue Aug 27, 2013 1:47 pm

API express change JSON result format

Post by Serhii Kulibaba »

You use incorrect JSON format, please use JSON below:
pre{
{"MenuName": "Food"},
{"MenuSub":[
{
"MenuSubID": 1,
"MenuSubName": "Fast Food"
},
{
"MenuSubID": 4,
"MenuSubName": "Food"
}
]}
}/pre

Post Reply