将Pig输出转换为JSON格式

时间:2021-02-27 14:05:38

I have the following output in Pig stored in a variable:

我在Pig中存储了以下输出变量:

("Keyword",
{
(data1, data2, data3, data4),
(data1, data2, data3, data4)
}
)

Expecting output in JSON format:

期望以JSON格式输出:

{
    "keyword": [
        {
            "val_1": "data1",
            "val_2": "data2",
            "val_3": "data3",
            "val_4": "data4"
        },
        {
            "val_1": "data1",
            "val_2": "data2",
            "val_3": "data3",
            "val_4": "data4"
        }
    ]
}

Any help will be appreciated.

任何帮助将不胜感激。

1 个解决方案

#1


4  

If you have defined a schema, all you got to do is -

如果您已经定义了架构,那么您所要做的就是 -

store yourRelation into 'file_location_in_hdfs' using JsonStorage();

This will use the schema, variable names as the json tags.

这将使用模式,变量名称作为json标记。

#1


4  

If you have defined a schema, all you got to do is -

如果您已经定义了架构,那么您所要做的就是 -

store yourRelation into 'file_location_in_hdfs' using JsonStorage();

This will use the schema, variable names as the json tags.

这将使用模式,变量名称作为json标记。