[Solved-1 Solution] How to Parse Complex JSON String in Pig ?



Json

  • A common use of JSON is to exchange data to/from a web server.
  • When sending data to a web server, the data has to be a string.

Problem:

How to Parse Complex JSON String in Pig ?

Solution 1:

  • We using JsonTupleMap() in Mozilla's Akela library for pig. It accomplishes exactly what we want by parsing all of JSON even when it's complex.

Example:

REGISTER '/path/to/akela-0.5-SNAPSHOT.jar';
DEFINE JsonTupleMap com.mozilla.pig.eval.json.JsonTupleMap();
loaded = LOAD '$INPUT' AS (json_string:chararray, ...);
jsonified = FOREACH loaded GENERATE JsonTupleMap(json_string) AS json:map[], ...;
some_generate = FOREACH jsonified GENERATE json#'key'#'sub_key';

Related Searches to How to Parse Complex JSON String in Pig