JSON Parser: Can it Parse JSON Array ?

1,594 views
Skip to first unread message

Girish Kumar

unread,
Jan 23, 2017, 12:14:28 AM1/23/17
to CDAP User
Hi,

I'm using JSON Parser 1.5.0 in the hydrator pipeline.  The input JSON has an array of JSON objects.  It looks like JSON Parser 1.5 doesn't parse the Array but expects just the JSON object individually.  I get this error when configured to parse JSON array (Below error log)

Q1: Isn't the JSON Parser designed to take JSON array of objects ?
Q2: Is there a alternative for parsing array of JSON objects ?
 
Regards,
/Girish BK

-------------

java.lang.Exception: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: com.jayway.jsonpath.PathNotFoundException: Expected to find an object with property ['name'] in path $['value'] but found 'net.minidev.json.JSONArray'. This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.
	at org.apache.hadoop.mapred.LocalJobRunnerWithFix$Job.runTasks(LocalJobRunnerWithFix.java:465) ~[co.cask.cdap.cdap-app-fabric-4.0.0.jar:na]
	at org.apache.hadoop.mapred.LocalJobRunnerWithFix$Job.run(LocalJobRunnerWithFix.java:524) ~[co.cask.cdap.cdap-app-fabric-4.0.0.jar:na]

leo...@cask.co

unread,
Jan 23, 2017, 8:13:12 PM1/23/17
to CDAP User
Hi, Girish,

Parsing json arrays are not supported in the current version of JSON parser. 
One alternative solution is to use Javascript transform plugin to parse the JSON.
Since JSON is a first class citizen in javascript you can parse it using JSON.parse(input.body)

Leonid
Reply all
Reply to author
Forward
0 new messages