Reputation: 21554
Say I have some moderately complex JSON like
{
"revenue": 100,
"products":[
{"name": "Apple", "price": 50},
{"name": "Banana", "price": 50}
]
}
Obviously this this a bit contrived, but what's the best way to map this to pig using JsonLoader.
I've tried
a = LOAD 'test.json' USING
JsonLoader('revenue:int,products:[(name:chararray,price:int)]');
or
a = LOAD 'test.json' USING
JsonLoader('revenue:int,products:[{(name:chararray,price:int)]}');
However, when I DUMP A
, I get (100,)
for both.
I've also tried
a = LOAD '/json/complex.json'
USING JsonLoader('revenue:int,products:[{name:chararray,price:int}]');
which errors out with ERROR 1200: <line 1, column 28> mismatched input 'chararray' expecting LEFT_PAREN
.
What's the best way to parse this for future use?
Thanks
Upvotes: 0
Views: 1527
Reputation: 21554
For posterity,
a = LOAD 'test.json' USING
JsonLoader('revenue:int,products:{(name:chararray,price:int)}');
Upvotes: 1