Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonStringToMap cannot handle JsonArrays #466

Open
aksbhatia opened this issue Jun 2, 2016 · 0 comments
Open

JsonStringToMap cannot handle JsonArrays #466

aksbhatia opened this issue Jun 2, 2016 · 0 comments

Comments

@aksbhatia
Copy link

aksbhatia commented Jun 2, 2016

Error:
Caused by: java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to org.json.simple.JSONObject
at com.twitter.elephantbird.pig.piggybank.JsonStringToMap.parseStringToMap(JsonStringToMap.java:63)
at com.twitter.elephantbird.pig.piggybank.JsonStringToMap.exec(JsonStringToMap.java:53)

Possible Reason:
protected Map<String, String> parseStringToMap(String line) {
try {
Map<String, String> values = Maps.newHashMap();
_JSONObject jsonObj = (JSONObject) jsonParser.parse(line);_

i.e. Since it is trying to cast JSONArray to JSONObject, it fails.

Eg. Input:
[{"discountLevel":"SUBTOTAL","itemIDs":["2523445"]},{"discountLevel":"SUBTOTAL","itemIDs":["1119882"]}]

My Pig Script:
a = FOREACH applied GENERATE JsonStringToMap(input);

Some googling led me here : https://groups.google.com/forum/#!topic/elephantbird-dev/mxCcAh4WEXY
Similar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant