I am trying to create some input data for an ApexChart (bar-Chart) from SQL query (of type: return single value). The bar chart would accept data input in the following form:
[ {x:"1 author", y:15 }, {x:"3 authors", y:55}, {x:"15 authors", y:25} ]
The SQL return similar to following result:
"[{x:"1", y:14},{x:"1", y:15},{x:"1", y:19}]"
If I directly copy SQL result from SQL Developer console and paste it in my script, it works fine, but that is not the cleanest way to do this task. Ideally, the data return from this query would better be directly read from file item in Apex and automatically get parsed in required input data format (i.e., array of objects). Let say, the hidden item name is "P3_ITEM".
P3_ITEM.value
will give us single value string concatenated result of SQL query.
"[{x:"1", y:14},{x:"1", y:15},{x:"1", y:19}]"
removing starting and ending double quotes wont solve, because it is still of type string. and converting this string to array of objects also doesn't work, because it is then array of strings not objects.
So, the question is, how to create an array of objects derived from this string value (single value sql result)?