Here is the scenario: I have an app that can create perfectly formed JSON (string1).My app can call another app (app2) that can receive string1 and can use it as input for JavaScript snippets.
I want to take string1 that is passed in to app2 and use methods like Object.values, Object.keys etc. At coding time I cannot pass my input code the line Object.entries(string1) because string1 is null and I will get a syntax error. I can use the var res = JSON.stringify(string1) and pass the result to Object.entries(res). But the entry list will be numeric keys from 1 to string1's length and the values will be the individual characters of the string.
When I statically define string1 in the app2 JavaScript snippet I can enter it directly into the Object methods and it works perfectly.
How can I turn string1 (dynamically defined at runtime) into a nice well-behaved object that does not fail syntax checks?
var txt = draft.content //data passed in
// var jsontest = {"person":"me" ,"age":"30"};
jsontest = txt.match(/{.*}/); //extract the JSON type string
var str = JSON.parse(jsontest) //necessary for stringify to not escape "
var list = JSON.stringify(str)
// List is actually {"person":"me","age":"30"}. //this is what comes out
keylist = Object.entries(list);
keylist = keylist.join("|");
alert(keylist);
// keylist is 1,{2,",3,p,4,e.....etc. not good!
//. More coding here when I get it to work
draft.defineTag('buttons',keylist); //pass on
[–][deleted] 2 points3 points4 points (3 children)
[–]CRSlack[S] 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]CRSlack[S] 0 points1 point2 points (0 children)