0
votes

I have the following type of json file:

{"employees":[
    {"firstName":"John", "lastName":"Doe"},
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter", "lastName":"Jones"}
]}

I am trying to execute the following pig script to load json data

A = load 'pigdemo/employeejson.json' using JsonLoader ('employees:{(firstName:chararray)},{(lastName:chararray)}');

getting error!!

Unable to recreate exception from backed error: Error: org.codehaus.jackson.JsonParseException: Unexpected end-of-input: expected close marker for ARRAY (from [Source: java.io.ByteArrayInputStream@1553f9b2; line: 1, column: 1]) at [Source: java.io.ByteArrayInputStream@1553f9b2; line: 1, column: 29]

1
what is the error you are getting - Satya
#Satya I have update the question - avijit
A = load 'pigdemo/employeejson.json' using JsonLoader ('employees:{(firstName:chararray),(lastName:chararray)}'); try this one!! - Ankur Alankar Biswal
2016-09-23 07:38:02,032 [main] INFO org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher - Failed! 2016-09-23 07:38:02,040 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 2997: Unable to recreate exception from backed error: AttemptID:attempt_1474637915471_0007_m_000000_3 Info:Error: org.codehaus.jackson.JsonParseException: Unexpected end-of-input: expected close marker for ARRAY (from [Source: java.io.ByteArrayInputStream@7a91efc3; line: 1, column: 1]) this is the error message i am getting @Ankur - avijit
try tthis @Avijit : A = load 'pigdemo/employeejson.json' using JsonLoader ('employees':{(firstName:chararray)},{(lastName:chararray)}); - Satya

1 Answers

1
votes

First the reason that you see Unexpected end-of-input is because each recode should be in 1 line - like this :

{"employees":[{"firstName":"John", "lastName":"Doe"}, {"firstName":"Anna", "lastName":"Smith"}, {"firstName":"Peter", "lastName":"Jones"}]}

Now - since each row is employees list run the next command

A = load '$flurryData' using JsonLoader ('employees:bag {t:tuple(firstName:chararray, lastName:chararray)}');
describe A;
dump A;

Give the next output

A: {employees: {t: (firstName: chararray,lastName: chararray)}}

({(John,Doe),(Anna,Smith),(Peter,Jones)})

Hope this help !