Author Message
VasilyL
Joined: Jul 11, 2016
Messages: 230
Offline
Hello Guys!

Can you please tell me if there is an option to check if JSON string contains required attribute?

The problem: we have a JSON String. Some attributes are optional.

In the JSON Parser element (which retrieve items from JSON String) I do not see such option.
So, from time to time I catch an exception like
30/08/2022 17:17:02:196 INFO - E8495272229B60B9B49A564B5AECDD1E:/MyApp: Capturing exception [com.avaya.sce.runtimecommon.SCERuntimeException]. Message [ERROR : Could not Parse JSON : org.json.JSONException: JSONObject["PROPERTY"] not found.org.json.JSONException: JSONObject["PROPERTY"] not found.
**** Root Cause
org.json.JSONException: JSONObject["PROPERTY"] not found.
at org.json.JSONObject.get(JSONObject.java:454)
at com.avaya.sce.pdc.json.operations.JSONParser.execute(JSONParser.java:137)
at com.avaya.sce.runtime.Data.evaluateActions(Data.java:237)

Even if I put JSON Parser element in
try{}
catch(*) I still see such exception in the trace log file.

Of cause we can use custom java code and jackson or gson lib, but it is quite convenient to use built-in JSON Parser in Data items.

Thanks in advance for you help!
Vasily.
WilsonYu
Joined: Nov 6, 2013
Messages: 3950
Offline
try/catch is the only option right now. You can suppress the exception in the log by setting the showcaughtexceptions property to disabled in the ddrt.properties file or in the report settings of EPM
VasilyL
Joined: Jul 11, 2016
Messages: 230
Offline
Hi,
Thank you very much!
massimo__croci
Joined: Jan 31, 2020
Messages: 518
Offline
Additionally, in case you need to check your JSON's format, take a look at

https://www.devconnectprogram.com/forums/posts/list/20580.page
VasilyL
Joined: Jul 11, 2016
Messages: 230
Offline
Thanks for the link.
Well, my question is not in JSON validation.
I have a little bit another question.
Anyway thank you for taking part in the discussion.
VasilyL
Joined: Jul 11, 2016
Messages: 230
Offline
Hi All,
Just to finalize the topic.
Wilson's answer does work well: try/catch is the only option right now. You can suppress the exception in the log by setting the showcaughtexceptions property to disabled in the ddrt.properties file or in the report settings of EPM

The only addition for my case is: if you use a simple IVR then it's okay to set up this option in the app option in EPM. But if you run your application as a POM application then you have to change the setting in the pomappdriver application in EPM.
Go to:   
Mobile view