I read a row from a database in Aqua Script and have the data in a datarow. One of the columns contains JSON as its data. I'd like to read that column out into a variable in Aqua Script and then be able to manipulate, really reference fields within the JSON and their field values. I've looked through many of the sample Aqua Script docs, but have not seen an example of manipulating JSON in this manner. I couldn't find an issue on the wiki either regarding JSON.
Separately, I did define a trivial JSON "object" into a variable and was able to look at those fields.
However, I'm not sure if that will work with a larger JSON retrieved from a database row column value and whether certain parsing is needed/recommended.
|
75 KB
|
94 KB
Hi Bob,
AquaScripts don't provide any specific Open APIs for JSON parsing. However because AquaScripts are JavaScripts plus OpenAPIs, you can use features of the JavaScript language. JavaScript provides a JSON.parse() method & below is an example that uses it along w/ the results. Let me know if this answers your question.
// JSON data in javaScript variable var jsonString = '{ "pageInfo" : { "pageName" : "abc" ,"pagePic" : "http://example.com/content.jpg" } ,' + '"posts" : [{"post_id" : 12345, "actor_id" : "544","page_id" : 977}]}'; //print the JSON data print(jsonString); //Parse the JSON data. var jsondata = JSON.parse(jsonString); //Get JSON data. print("PageName : " + jsondata.pageInfo.pageName); print("PagePic : " + jsondata.pageInfo.pagePic); print("Post_id : " + jsondata.posts[0].post_id); print("Actor_id : " + jsondata.posts[0].actor_id);
Also attached is an example of reading JSON data from file & then using JSON.parse()
Issue #15334 |
Closed |
Fixed |
Resolved |
Completion |
No due date |
No fixed build |
No time estimate |
Hi Bob,
AquaScripts don't provide any specific Open APIs for JSON parsing. However because AquaScripts are JavaScripts plus OpenAPIs, you can use features of the JavaScript language. JavaScript provides a JSON.parse() method & below is an example that uses it along w/ the results. Let me know if this answers your question.
Also attached is an example of reading JSON data from file & then using JSON.parse()