So I’m trying to parse JSON from a variable in memory , the parsing works in the Data Viewer and I can see the results, but in the script it does not.
I am parsing the elements into TEXT fields in my database.
Here is partial JSON:
indent preformatted text by 4 spaces
{
“RECORDS”:[
{
“Company or Entity”:“Anthem, Inc. Affiliated Covered Entity”,
“Total Records Compromised”:“78800000”,
“Latest Public Disclosure”:“03/13/15 00:00:00”
},
{
“Company or Entity”:“Premera Blue Cross”,
“Total Records Compromised”:“11000000”,
“Latest Public Disclosure”:“03/17/15 00:00:00”
},
{
“Company or Entity”:“Excellus Health Plan, Inc.”,
“Total Records Compromised”:“10000000”,
“Latest Public Disclosure”:“09/09/15 00:00:00”
},
indent preformatted text by 4 spaces
I believe that @samfmp has correctly identified the issue.
+1 to using Set Field instead of Insert Calculated Result.
Other observations which I hope will be helpful:
If ever the supplied JSON contains no records, the script (as shown above) will create a blank record.
If ever the supplied JSON is mal-formatted, the script may create a small number of garbage records.
The cause for observation #1 is that the test to exit the loop occurs after the New Record step.
The cause for observation #2 is that mal-formatted JSON can result in JSONListKeys returning an error message of several lines in length. The result is that the variable $counter will be set to some small value equal to the number of lines in the error message.
LOL … This looks like data I posted a while back on Hacks and compromised records.
I noticed two problems: (1) your JSON (forum text posting problem?) and your script.
FWIW, I had these data in a MySQL database so I did all the calculations using rocket-fast MySQL – eliminating clumsy JSON processing.
Problem 1: the JSON
I noticed … your JSON itself has issues and would not validate. In particular, the JSON’s quotes are not straight. Don’t use curly quotes – could be a forum text posting problem.
I modified your JSON slightly, and using the updated script below, it works now (I posted a screenshot since it seems that when I post straight quotes, this forum converts them to curly quotes which will NOT work in JSON. I also completed the end of the JSON.
(@Cecile: is this curly quotes issue a forum text posting problem?)
Thanks fmpdude and other who replied.
The JSON is fine, it works in the Data Viewer and formats perfectly.
(maybe because of posting in the forum it changes over to curly quote marks)
Finally it was fmpdudes solution which worked. Instead of "RECORDS[$index].Company or Entity" Should have written it as “RECORDS[ “& $index” &].Company or Entity”.