Genesys Cloud - Main

 View Only

Sign Up

  • 1.  jsonParse function and error handling

    Posted 21 days ago

    Hi,

    I am trying to use the "JsonParse" function in Architect.
    The help documentation says, that for the parameter passed to the function: "Parameter String valueToParse : The String value to parse to a JSON value. Supplying a blank string to JsonParse will invoke error handling."

    It doesn't mention that a badly formed json string will invoke error handling.
    But in the tests I have done, if I pass a badly formed json string (e.g. JsonParse("{\"account\": \"12345678\" \"name\": \"John Doe\"}"), error handling seems to be invoked.

    (JsonParse("{\"account\": \"12345678\", \"name\": \"John Doe\"}") works well).

    I can understand why the badly a formed json string would invoke error handling, but I can see no way to qualify the validity of the string before passing it to "jsonParse".
    I have no control over the string that is being parsed (it comes from an external system), which means that I have no way to avoid error handling if the remote system doesn't provide valid "stringified" json.

    Does anybody know a way to qualify the string to be parsed so that error handling can be avoided?


    #ArchitectandDesign

    ------------------------------
    Andrew Watson
    Architect
    ------------------------------


  • 2.  RE: jsonParse function and error handling
    Best Answer

    Posted 21 days ago

    Hello Andrew, 

    I believe this is a limitation in Architect's JSON handling. Architect doesn't really provide a built-in way to validate JSON strings before parsing them. 

    I can think of a "work" around for this by using the error handling block. The most reliable approach is to wrap your JsonParse operation in an error handling block. This way you can handle both blank strings and malformed JSON. You can then decide what to do when invalid JSON is received (example: log the error, use a default value, etc.)

     But I highly recommend submitting a feature request to our ideas lab for a built in way to validate json strings as this sounds like a great feature to have. 

    Hope this helps!



    ------------------------------
    Cameron
    Online Community Manager/Moderator
    ------------------------------



  • 3.  RE: jsonParse function and error handling

    Posted 21 days ago

    Thanks for your response Cameron.

    The error handling block sounds ideal. It sounds like a try/catch functionality. 


    Sorry for my ignorance, but I am not familiar with the "error handling block".
    Is it the "Event Handling" in the flow (I am using an email flow, so my only choice is to route to a fallback queue - or disconnect).
    Or is it an object I should be able to select from the architect toolbox.
    Or is it something completely different :-) ?

    Thanks again.



    ------------------------------
    Andrew Watson
    Architect
    ------------------------------



  • 4.  RE: jsonParse function and error handling

    Posted 21 days ago

    Hello Andrew, 

    Sorry about I made that sound confusing. Error handling is actually part of the flow's properties and not a separate block in the toolbox. 

    Cheers, 



    ------------------------------
    Cameron
    Online Community Manager/Moderator
    ------------------------------



  • 5.  RE: jsonParse function and error handling

    Posted 19 days ago

    No worries Cameron.

    Thanks for the feedback.

    Cheers

    Andrew Watson



    ------------------------------
    Andrew Watson
    Architect
    ------------------------------