Utilizing app script to retrieve data from an API and convert it into JSON format.
var data = UrlFetchApp.fetch(***);
var obj = JSON.parse(data); // Convert to JSON
Logger.log(typeof(obj)); // Returns object type
Here is an example of the returned JSON array:
var dataJson = [{age=20, gender=female, country=usa, name=sali, type=female},{age=25, gender=male, country=usa, name=john, type=female},{age=19, gender=female, country=usa, name=anita, type=female},{age=22, gender=male, country=usa, name=fredo, type=female}]
If gender is female, change the country to UK. If gender is male, change the country to Canada.
After updating the array, ensure that 'type' remains as an object, not a string.
The updated result would be:
[{age=20, gender=female, country=uk, name=sali, type=female},{age=25, gender=male, country=canada, name=john, type=female},{age=19, gender=female, country=uk, name=anita, type=female},{age=22, gender=male, country=canada, name=fredo, type=female}]
Please note: the data is dynamic and subject to change.