You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Henry Chen <nt...@gmail.com> on 2015/03/09 19:54:51 UTC
elephantbird parse nested json question
Hi all,
I have a json format input.txt looks like this:
{
"character_guid":12345,
"stat_key":"thank_you_mario",
"logged_at":43475,
"metrics":{
"but_our_princess":{
"amount":{
"value":1,
"timestamp":43414
}
},
"is_in_another_castle":{
"amount":{
"value":1,
"timestamp":43424
}
}
}
}
Here's my pig script to load the data:
raw_data = LOAD 'input.txt' USING
com.twitter.elephantbird.pig.load.JsonLoader('-nestedLoad') AS
(json:map[]);
data = FOREACH raw_data GENERATE json#'character_guid' AS
(character_guid:chararray), json#'stat_key' AS (stat_key:chararray),
json#'logged_at' AS (logged_at:chararray), FLATTEN(json#'metrics') AS
(metrics:map[]);
>From that, my question is how to get the output looks like the following:
(12345, thank_you_mario, 43475, but_our_princess, 1, 43414)
(12345, thank_you_mario, 43475, is_in_another_castle, 1, 43424)
Thanks for your answer!