sort JSON object keys by name
Question

Hey,

I have a JSON object after serializing it in "JSONSerialize" action , is there a way to create a string from this object with the keys in the object being sorted in alphabetic way ? also i need to create this string without separators and concatenated, for example my JSON object:

{"signature":"dsf54sd5f4ds56f4","shipping_charges":"1.000","account_id":"123456","customer_shipping_state":"","reference_id":"5t097doz7dkDU_20_0"} 

my desired output i'm looking to create is:

account_id123456customer_shipping_statereference_id5t097doz7dkDU_20_0shipping_charges1.000signaturedsf54sd5f4ds56f4 

thanks!

Hello 

If you want to convert your json object to string you can achieve this by JavaScript

check this if it helps

1) Store your string into local variable 

2) Add a button that will call Js and pass your string into your JS and take a output at the end

code snippet - 


const txt = '{"name":"John", "age":30, "city":"New York"}'

const obj = JSON.parse(txt);

var parseString = obj.name + obj.age;


And check this 


var myObj = {"signature":"dsf54sd5f4ds56f4","shipping_charges":"1.000","account_id":"123456","customer_shipping_state":"","reference_id":"5t097doz7dkDU_20_0"} ,

  keys = Object.keys(myObj),

  i, len = keys.length;


keys.sort();


for (i = 0; i < len; i++) {

  k = keys[i];

  console.log(k + myObj[k]);

}


Also you can checkout to this Forge hope it works - 

https://www.outsystems.com/forge/component-overview/969/json-pretty-format

I hope this helps

Thanks


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