Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
in the sample app in Enhanced JSON Tool Plugin . follow the pic example and switch response type to JSON in process 2, there's a beanshell there. Compare the beanshell with the JSONSample.txt under Resources in the App Composer. Think you can get the gist of it, then modify that in accordance to your JSON format.
Hi, tkx for your response!
I am quite a newby, so a little bit dazzled about the different approach as suggested by John Smith. I try to follow and understand the example, but at the resource the link JSONsample.txt gives a 404. The file is missing.
The demo app actual gives the same 404 result when starting the process :
2232
INFO 07 aug. 2024 11:13:28 org.joget.apps.app.service.AppDevUtil - Commit to Git repo by admin: Update package Enhanced_JSON_Tool_NEW. _
2233
INFO 07 aug. 2024 11:13:44 org.joget.marketplace.EnhancedJsonTool - GET : http://192.168.1.143:8080/jw/web/app/json_tool_dx_kb/resources/JSONsample.txt
2234
INFO 07 aug. 2024 11:13:44 org.joget.marketplace.EnhancedJsonTool - http://192.168.1.143:8080/jw/web/app/json_tool_dx_kb/resources/JSONsample.txt returned with status : 404
When I try to follow the example, I come to undermentioned script, but gives a parsing error on line 9.
********
import org.joget.workflow.model.service.*;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import java.util.*;
Map parent = new HashMap();
Collection arr = new ArrayList();
for(Map obj : data.get("adressen")){
//get any values from "value" array
Map col = new HashMap();
col.put("oospronkelijkBouwjaar", obj.get("oospronkelijkBouwjaar"));
}
//put the new map into "data"
parent.put("data", arr.toArray());
return parent;
*********
ERROR 07 aug. 2024 11:33:25 org.joget.marketplace.EnhancedJsonTool - Error executing script
2247
bsh.EvalError: Sourced file: inline evaluation of: ``import org.joget.workflow.model.service.*; import org.json.simple.JSONObject; . . . '' : The collection, array, map, iterator, or enumeration portion of a for statement cannot be null.
Oh right...it was awhile back...but I think the url path in the enhanced json plugin is wrong...the right path should be in the resources. In the resources, click on jsonsample.txt and you should see the url path. Copy that and paste it in the enhanced json tool in the process builder. And the default beanshell should work against that file.
I think your _embedded object is an array and it contains another array called addressen ? From the snippet code in the error...looks like it's abit wrong there
Thank you for your help.
I tried this, but gave undermentioned new error message. I probably forget some declaration or something?
ERROR 04 aug. 2024 23:41:23 org.joget.marketplace.EnhancedJsonTool - Error executing script
bsh.EvalError: Sourced file: inline evaluation of: ``import org.json.JSONObject; import org.json.JSONArray; String jsonResponse = . . . '' : Typed variable declaration : Error in method invocation: Method getVariable( java.lang.String ) not found in class'org.joget.workflow.model.WorkflowAssignment'
hi,
To handle the issue with the _embedded
key in your JSON response, you can use a BeanShell script in the Enhanced JSON Tool. Here's a short script example:
import org.json.JSONObject;
import org.json.JSONArray;
String jsonResponse = (String) workflowAssignment.getVariable("jsonResponse");
JSONObject jsonObject = new JSONObject(jsonResponse);
JSONObject embedded = jsonObject.getJSONObject("_embedded");
JSONArray adressenArray = embedded.getJSONArray("adressen");
JSONObject firstAddress = adressenArray.getJSONObject(0);
String oorspronkelijkBouwjaar = firstAddress.getJSONArray("oorspronkelijkBouwjaar").getString(0);
workflowAssignment.setVariable("oorspronkelijkBouwjaar", oorspronkelijkBouwjaar);
This script gets the JSON response, navigates through the _embedded
key, and extracts the oorspronkelijkBouwjaar
value. Just add this script to the "Script" section of the Enhanced JSON Tool, bind the jsonResponse
variable to your API response, and use the oorspronkelijkBouwjaar
variable in your form.
let me know how it goes
When accessing a government API, the response is a JSON object which starts with "_embedded". To retrieve an underlaying object I have to identify the JSON Object Name starting with "_embedded" (e.g. "_embedded.adressen.oorspronkelijkBouwjaar". The systems gives an error when using _embedded. Without it is not able to retrieve the object and the form field just contains the object name.
It looks like the JSON Tool crashed on the word "_embedded". Iḿ not that experienced to write a beanshell in the Enhanced JSON Tool to replace this word and see if it solves the issue. Can somebody assist with this issue?
This is part of the system log:
INFO 01 aug. 2024 10:02:19 org.joget.apps.app.lib.JsonTool - GET : https://api.bag.kadaster.nl/lvbag/individuelebevragingen/v2/adressenuitgebreid?huisnummer=13&postcode=9999ZZ&exacteMatch=false
2016INFO 01 aug. 2024 10:02:19 org.joget.apps.app.lib.JsonTool - Adding request header X-Api-Key : ---removed---
2017INFO 01 aug. 2024 10:02:19 org.joget.apps.app.lib.JsonTool - Adding request header Accept-Crs : epsg:28992
2018INFO 01 aug. 2024 10:02:19 org.joget.apps.app.lib.JsonTool - Adding request header Accept : application/hal+json
2019INFO 01 aug. 2024 10:02:19 org.joget.apps.app.lib.JsonTool - https://api.bag.kadaster.nl/lvbag/individuelebevragingen/v2/adressenuitgebreid?huisnummer=13&postcode=9999ZZ&exacteMatch=false returned with status : 200
2020INFO 01 aug. 2024 10:02:19 org.joget.apps.app.lib.JsonTool - {"_embedded":{"adressen":[{"openbareRuimteNaam":"Teststraat","korteNaam":"Teststraat","huisnummer":13,"postcode":"9999ZZ","woonplaatsNaam":"Amsterdam","nummeraanduidingIdentificatie":"0010200000103316","openbareRuimteIdentificatie":"0010300000000643","woonplaatsIdentificatie":"3234","adresseerbaarObjectIdentificatie":"0010010000053069","pandIdentificaties":["0010100000007134"],"adresregel5":"Teststraat 13","adresregel6":"9999 CN AMSTERDAM","typeAdresseerbaarObject":"Verblijfsobject","adresseerbaarObjectGeometrie":{"punt":{"type":"Point","coordinates":[255191.0,593318.0,0.0]}},"adresseerbaarObjectStatus":"Verblijfsobject in gebruik","gebruiksdoelen":["woonfunctie"],"oppervlakte":245,"oorspronkelijkBouwjaar":["2000"],"pandStatussen":["Pand in gebruik"],"_links":{"self":{"href":"https://api.bag.kadaster.nl/lvbag/individuelebevragingen/v2/adressenuitgebreid/0010200000103316"},"openbareRuimte":{"href":"https://api.bag.kadaster.nl/lvbag/individuelebevragingen/v2/openbareruimten/0010300000000643"},"nummeraanduiding":{"href":"https://api.bag.kadaster.nl/lvbag/individuelebevragingen/v2/nummeraanduidingen/0010200000103316"},"woonplaats":{"href":"https://api.bag.kadaster.nl/lvbag/individuelebevragingen/v2/woonplaatsen/3234"},"adresseerbaarObject":{"href":"https://api.bag.kadaster.nl/lvbag/individuelebevragingen/v2/verblijfsobjecten/0010010000053069"},"panden":[{"href":"https://api.bag.kadaster.nl/lvbag/individuelebevragingen/v2/panden/0010100000007134"}]}}]},"_links":{"self":{"href":"https://api.bag.kadaster.nl/lvbag/individuelebevragingen/v2/adressenuitgebreid?huisnummer=13&postcode=9999ZZ&exacteMatch=false"}}}
2021ERROR 01 aug. 2024 10:02:19 org.joget.apps.app.lib.JsonTool - java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class java.util.Map ([Ljava.lang.Object; and java.util.Map are in module java.base of loader 'bootstrap')
2022java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class java.util.Map ([Ljava.lang.Object; and java.util.Map are in module java.base of loader 'bootstrap')
2023 at org.joget.apps.app.lib.JsonTool.getObjectFromMap_aroundBody18(JsonTool.java:261) ~[classes/:?]
2024 at org.joget.apps.app.lib.JsonTool.getObjectFromMap_aroundBody19$advice(JsonTool.java:102) ~[classes/:?]
2025 at org.joget.apps.app.lib.JsonTool.getObjectFromMap(JsonTool.java:1) ~[classes/:?]