用Pig解析“复杂" JSON [英] Parsing 'Complex' JSON with Pig

查看:144
本文介绍了用Pig解析“复杂" JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一些中等复杂的JSON,例如

Say I have some moderately complex JSON like

{
    "revenue": 100,
    "products":[
            {"name": "Apple", "price": 50},
            {"name": "Banana", "price": 50}
    ]
}

显然,这有点做作,但是使用JsonLoader将其映射到Pig的最佳方法是什么.

Obviously this this a bit contrived, but what's the best way to map this to pig using JsonLoader.

我尝试过

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

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

但是,当我DUMP A时,两者都得到(100,).

However, when I DUMP A, I get (100,) for both.

我也尝试过

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

其中的错误出现在ERROR 1200: <line 1, column 28> mismatched input 'chararray' expecting LEFT_PAREN上.

解析此信息以备将来使用的最佳方法是什么?

What's the best way to parse this for future use?

谢谢

推荐答案

对于后代,

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

这篇关于用Pig解析“复杂" JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆