In my pipelet I make a REST call to a 3rd party system and get back a String containing the JSON response. From the JSON I want to parse 1 attribute. What is the best way to parse JSON on Intershop Commerce Management 7.8?
What is the recommended way to parse JSON on Intershop?
208 views Asked by Kurt Rätzsch At
2
There are 2 answers
0
On
Jackson is definitely recommended, but for very simple cases you could alternatively use org.json.
Example:
JSONObject obj = new JSONObject(responseAsStr);
String accessToken = obj.getString("access_token");
However, this library is not included by default. You have to include it in build.gradle of your cartridge, e.g.:
compile group: 'org.json', name: 'json', version: '20090211'
Intershop includes the Jackson library. You can use it without even need to map the whole response to a well-defined object, but you can parse it "on the fly". See "Jackson JSON – Read Specific JSON Key" paragraph here: http://www.journaldev.com/2324/jackson-json-java-parser-api-example-tutorial