Hello Every one, How can we convert the below JSON...
# suitescript
n
Hello Every one, How can we convert the below JSON to Simple JSON using Javascript?? Please let me know if any one have any code of website to refer!!
JSON:
{
"custcol_vendormemo": "Qty 8 - B/O Cancelled,
"statusref":
[
{
"value": "partiallyReceived",
"text": "Partially Received"
}
]
}
Simple JSON:
{
"custcol_vendormemo": "Qty 8 - B/O Cancelled,
"statusref" : "Partially Received"
}
Thanks in Advance!
s
I'm not sure if this is what you're looking for but this satisfies your requirement. This is only going to work in SS2.1 ClientScript files where you have access to arrow functions, let and const.
r
I do something similar to "flatten" json from saved search results.
Copy code
function flattenResults(results){

        //get into native JS objects
        var resultsObj = JSON.parse(JSON.stringify(results));

        resultsObj.forEach(function(result) {
                for (const [key, value] of Object.entries(result.values)) {
                        if (Array.isArray( result.values[key]) ) {

                                result.values[key] =result.values[key].length;
                                if( result.values[key].length != 0) {
                                        try{
                                                result.values[key] = value[0].text;
                                                result.values[key+".value"] = value[0].value;
                                                log.debug(`${key}`, value[0].text);

                                        }catch (e){}
                                }
                        }

                }
        })
        return resultsObj;

}
n
Okay this will give me text value of every result column of the saved search right??
r
I modified Tim's Saved Search api
and aded that function
Copy code
if(request.flatten == 'true') {
        results = flattenResults(resultSet.getRange({start: start, end: start + 1000}));
}else {
        results = resultSet.getRange({start: start, end: start + 1000});

}
and pass in "flatten" : "true" on the request.
n
okay thanks guys