Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A Pig to JSON UDF for Pig that converts tuples and bags to JSON strings
Latest commit 0789613 @rjurney Update
Failed to load latest commit information.
dist/lib Bugfix
src/com/hortonworks/pig/udf Ship it
.gitignore Committing for askign Thejas
Pig-to-json.iml Pushing what I got Update
build.xml Pushing what I got
ivy.xml Pushing what I got
test.pig More examples


A Pig to JSON UDF for Pig that converts tuples and bags to JSON strings. This code is free under the Apache 2.0 license.

This project likely borrows (I'm not sure, its been a while since I started it and I looked at lots of stuff) from the following projects:

Building the Project

ant clean
ant dist

Using the ToJson UDF

The file test.pig is illustrative:

/* Load Avro jars and define shortcut */
register /me/Software/pig/build/ivy/lib/Pig/avro-1.5.3.jar
register /me/Software/pig/build/ivy/lib/Pig/json-simple-1.1.jar
register /me/Software/pig/contrib/piggybank/java/piggybank.jar
define AvroStorage;

register /me/Software/pig-to-json/dist/lib/pig-to-json.jar

-- Available at
emails = load '/me/Data/enron.avro' using AvroStorage();
emails = limit emails 10;
json_test = foreach emails generate message_id, com.hortonworks.pig.udf.ToJson(tos) as bag_json;
dump json_test

emails2 = load '/me/Data/enron.avro' using AvroStorage();
emails2 = limit emails2 10;
json_test2 = foreach emails2 generate message_id, com.hortonworks.pig.udf.ToJson(from) as tuple_json;
dump json_test2
Something went wrong with that request. Please try again.