[Progress Communities] [Progress OpenEdge ABL] Forum Post: JSON ObjectModelParser crashes, what am I doing wrong?

Status
Not open for further replies.
J

Jeroen Eeuwes

Guest
Hi everybody, I'm writing a program that will receive a JSON and take some actions depending on the contents of the JSON. One of the first steps I want to do is validate that I did actually get a JSON. So reading the docs about ObectModelParser:parse() at Parse( ) method and read the following lines: "The returned value is either a JsonObject or a JsonArray. If the JSON syntax is incorrect, a JsonParserError is raised." Exactly what I want and so I implemented it. When testing it looks like the ObjectModelParser doesn't always recognises that a file isn't valid JSON and even worse it sometimes crashes the entire session. Below some simple code to illustrate this. In test 1 it does correctly recognise the JSON is valid, in test 2, 3 and 4 it will correctly say the JSON is invalid. In test 5 and 6 it will incorrectly say the JSON is valid and with test 7 you get a crash with a protrace stating: Exception code: C0000005 ACCESS_VIOLATION Fault address: 0FDFB5D8 01:0066A5D8 C:\Progressx86\OpenEdge\bin\prow32.dll As far as I can find it will always crash if the input starts with a number. I I remove the NO-ERROR from the parse statement it will generate the errors but test 7 still crashes. In my case the JSON should always be an object so if I test if the first character is a { I can circumvent the crash, but I'd rather not build my own JSON validator for all other possible things that could go awry. What am I doing wrong? I've tried this on 11.5 and 11.6 but not on 11.7. Test code below: USING Progress.Json.ObjectModel.*. DEF VAR cTest AS CHARACTER NO-UNDO. cTest = '~{"name": "value", "number": 123}'. RUN TestJson(1, cTest). cTest = 'abcd~{"name": "value", "number": 123}'. RUN TestJson(2, cTest). cTest = '~{"name": "value", abcd, "number": 123}'. RUN TestJson(3, cTest). cTest = '~{"name": "value", 123, "number": 123}'. RUN TestJson(4, cTest). cTest = '~{"name": "value", "number": 123}abcd'. RUN TestJson(5, cTest). cTest = '~{"name": "value", "number": 123}1234'. RUN TestJson(6, cTest). /* This results in a crash */ cTest = '1234~{"name": "value", "number": 123}'. RUN TestJson(7, cTest). PROCEDURE TestJson: DEFINE INPUT PARAMETER piNmbr AS INTEGER NO-UNDO. DEFINE INPUT PARAMETER pcTest AS LONGCHAR NO-UNDO. DEF VAR oParser AS ObjectModelParser NO-UNDO. DEF VAR oJsonConstruct AS JsonConstruct NO-UNDO. DEF VAR lJsonOK AS LOGICAL NO-UNDO. oParser = NEW ObjectModelParser(). oJsonConstruct = oParser:parse(cTest) NO-ERROR. IF VALID-OBJECT(oJsonConstruct) = FALSE OR oJsonConstruct = ? OR ERROR-STATUS:ERROR = TRUE OR ERROR-STATUS:NUM-MESSAGES > 0 THEN lJsonOk = FALSE. ELSE lJsonOk = TRUE. MESSAGE "Test number: " piNmbr SKIP "Is the Json OK? " lJsonOK SKIP(1) cTest VIEW-AS ALERT-BOX. CATCH errtest AS Progress.Lang.Error: DEF VAR iLoop AS INTEGER NO-UNDO. DO iLoop = 1 TO errtest:NumMessages: MESSAGE "Parser error" SKIP "error: " STRING(iLoop) SKIP errtest:GetMessage(iLoop) VIEW-AS ALERT-BOX. END. END CATCH. END PROCEDURE. Best regards, Jeroen

Continue reading...
 
Status
Not open for further replies.
Top