go to post Pedro Borges · Aug 14, 2017 Jon -- Yes, there were two entries that had invalid characters...Thanks for the tip! Eduard -- Thank you so very much for helping me on this!
go to post Pedro Borges · Aug 14, 2017 I do not have the %request object... the call to retrieve the JSON string is not using Cache's %Net.HttpRequest.At least that is what I understood you asked me to do. 8-)How the snippet of code (using $fromJSON) would be modified to incorporate your suggestion?Pedro
go to post Pedro Borges · Aug 14, 2017 Hello! I made good progress and the code works with small files (less than 32K characters). When I try to load the full file I get the following error... Error. Unable to parse file /tmp/pictures.json Error type Escaped hex sequence too large Error code 7 Error location Line 1 Offset 29356 For example, when I use this snippet of code... n r !,"Filename: ",filename Q:filename="" s stream=##class(%Stream.FileCharacter).%New() s sc=stream.LinkToFile(filename) i ('sc) W "Error on linking file "_filename,! Q try { S array=[].$fromJSON(stream) S iter=array.$getIterator() while iter.$getNext(.key,.value) { write !,"key "_key_":"_value."id",! } ; } catch ex { w "Unable to parse file "_filename,! w "Error type: "_ex.Name,! w "Error code: "_ex.Code,! w "Error location: "_ex.Location,! set obj="" } Q It will work for small.json but error-out for file all.json (Error: Escaped hex sequence too large)... -rw------- 1 pborges user 1037250 Aug 14 14:08 /tmp/all.json -rw------- 1 pborges user 28750 Aug 14 14:07 /tmp/small.json So, the question is... how to parse a really long JSON string? (>1M+ characters) BTW, the result I get from the REST call is stored in a global and I am saving it to a "flat" file at the OS level to concatenate in a long string. What I tried 1st was to parse the global, but there is not a clear end for each entry. For example... ZW ^result(1) ^result(1)= "{""id"":""0107454"",""title"":""John Smith"",""image_uri"":""https://<some URL>"",""image_timestamp"":""1496781334"",""image_url"":""https://<so ZW ^result(2) ^result(2)= "me URL>"",""is_restricted_under_18_only"":false,""is_restricted_adult_only"":false},{""id"":""01135433"" ... Because the node #1 reached 32,000 characters, a new node gets created to have the remainder of the result (I have 42 nodes in total).
go to post Pedro Borges · Aug 14, 2017 I am getting error: <THROW>zfromJSON+28^%Library.AbstractObject.1 *%Exception.General Parsing error 3 Line 1 Offset 1Below is the "raw" file I am using (stripped down to just two entries)... /tmp/small.json [{"id": "12345","title": "John Smith","image_uri": "https://<some URL>","image_timestamp": "1496781334","image_url":"https://<some URL>","is_restricted_under_18_only": false,"is_restricted_adult_only": false},{"id": "67890","title": "Mary Jane","image_uri": "https://<some URL>","image_timestamp": "1496781334","image_url": "https://<some URL>","is_restricted_under_18_only": false,"is_restricted_adult_only": false}] I tried to run this code... N filename,ex S filename="/tmp/small.json" try { S array=[].$fromJSON(filename) } catch ex { W !," Type: "_ex.Name W !," Code: "_ex.Code W !,"Location: "_ex.Location } Q This is the output... Type: Parsing error Code: 3Location: Line 1 Offset 1 Is the file malformed? What is wrong with line 1 offset 1? Pedro
go to post Pedro Borges · Aug 14, 2017 I get the error: <METHOD DOES NOT EXIST> *%FromJSON,%Library.Array I am running: Cache for UNIX (IBM AIX for System Power System-64) 2016.1.4 (Build 104) Mon Jun 19 2017 16:34:17 EDT
go to post Pedro Borges · Aug 14, 2017 I get the error: <METHOD DOES NOT EXIST> *%FromJSON,%Library.ArrayI am running the following Cache' version: Cache for UNIX (IBM AIX for System Power System-64) 2016.1.4 (Build 104) Mon Jun 19 2017 16:34:17 EDT