Page 1 of 2

API express change JSON result format

Posted: Wed Nov 09, 2016 11:25 am
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


API express change JSON result format

Posted: Wed Nov 09, 2016 1:31 pm
by Serhii Kulibaba

Hello,

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


API express change JSON result format

Posted: Wed Nov 09, 2016 1:56 pm
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


API express change JSON result format

Posted: Wed Nov 09, 2016 1:58 pm
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)


API express change JSON result format

Posted: Wed Nov 09, 2016 2:49 pm
by Takis

API express change JSON result format

Posted: Wed Nov 09, 2016 2:49 pm
by Takis

API express change JSON result format

Posted: Wed Nov 09, 2016 2:50 pm
by Takis

API express change JSON result format

Posted: Wed Nov 09, 2016 3:15 pm
by Takis

Or can by done in a Script component?


API express change JSON result format

Posted: Wed Nov 09, 2016 9:28 pm
by Takis

Any feedback please. Should have been easy.


API express change JSON result format

Posted: Thu Nov 10, 2016 12:50 pm
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