How to convert javascript text output to list
Question
Application Type
Mobile

Hi all,

How to convert the javascript text output to the list in Outsystems?

Javascript function output: "[{"item":{"Value":"karan"},"refIndex":0},{"item":{"Value":"khij"},"refIndex":1},{"item":{"Value":"kaustubh"},"refIndex":2},{"item":{"Value":"karan"},"refIndex":5},{"item":{"Value":"khij"},"refIndex":6},{"item":{"Value":"kaustubh"},"refIndex":7}]"

I want to convert this into list so that I can access the "Value" parameter in the screen. I used the JSON deserialize but not sure what datatype needs to be set in JSON deserialize action.

mvp_badge
MVP
Solution

Hi Kaustubh,

For the mentioned use-case, follow the below steps:

Implementation Steps

1) Create a structure based on the shared JSON string, using the Add Structure from JSON option

2) When you deserialize the JSON string, make sure that you set the Data type as Structure List Type as shown below 

3) After Deserializing the JSON string, assign the Ouptut to the Structure List type Local variable

See this sample screen JSON

Refer to the attached .oml file


I hope this helps you!


Kind regards,

Benjith Sam

PWAJSON.oml

Hi Kaustubh,

which values from the output you want to put in a list?

karan, khij, kaustubh, karan, khij, kaustubh ?

Regards

Yes jose, only the values karan, khij, kaustubh, karan, khij, kaustubh 

mvp_badge
MVP


Hello Kaustubh,

You have a couple of options. If you want to return the list as is, you can create a structure like this:

(make sure to set the JSON... property on the items). You can then use JSONDeserialize

-Or- if you want to return a list of just the values, you can use JavaScript like:

GetList().map(function(x) { return x.item.Value; });


mvp_badge
MVP
Solution

Hi Kaustubh,

For the mentioned use-case, follow the below steps:

Implementation Steps

1) Create a structure based on the shared JSON string, using the Add Structure from JSON option

2) When you deserialize the JSON string, make sure that you set the Data type as Structure List Type as shown below 

3) After Deserializing the JSON string, assign the Ouptut to the Structure List type Local variable

See this sample screen JSON

Refer to the attached .oml file


I hope this helps you!


Kind regards,

Benjith Sam

PWAJSON.oml

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.