JSON array to spinJson and back to JSON in Javascript

I am storing a JSON Object as Spin Json. The arrays in my original JSON objects are changing to Object . I can’t find a way back to convert SpinJSON object back to original JSON for the arrays inside object.

e.g. Original Object:-

{
“name”: “Bob”,
“citiesVisited”: [“New York”, “LA”, “London”]
}

When I use Spin over it, it gets converted to :-

{
“name”: “Bob”,
“citiesVisited”: {
“0”: “New York”,
“1”: “LA”,
“2”: “London”
}
}

Is there a way to convert
“citiesVisited”: {
“0”: “New York”,
“1”: “LA”,
“2”: “London”
}
back to “citiesVisited”: [“New York”, “LA”, “London”].

I have tried for loop but not satisfied with approach i used.

var keys = Object.keys(citiesVisited);
var cities = []
for (var x = 0; x < keys.length; x++) {
	cities.push(citiesVisited[cities[x]])
}
citiesVisited = cities;

Any help is really appreciated.

Please note I am using javascript in camunda modeler for this.

you can try using javascript

JSON.parse(cities)

It returns a jsonObject .

1 Like