Parsing 'Complex' JSON with Pig

时光总嘲笑我的痴心妄想 提交于 2019-12-08 11:20:44

问题


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


回答1:


For posterity,

a = LOAD 'test.json' USING
    JsonLoader('revenue:int,products:{(name:chararray,price:int)}');


来源:https://stackoverflow.com/questions/14094768/parsing-complex-json-with-pig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!