Skip to content

Instantly share code, notes, and snippets.

@hgschmie
Created July 24, 2012 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hgschmie/3173456 to your computer and use it in GitHub Desktop.
Save hgschmie/3173456 to your computer and use it in GitHub Desktop.
public class Jacksonian
{
public static void main(String[] args) throws Exception
{
final JsonFactory jf = new JsonFactory();
final ObjectMapper mapper = new ObjectMapper();
final JsonParser jp;
if(args.length > 0) {
jp = jf.createJsonParser(new File(args[0]));
}
else {
jp = jf.createJsonParser(System.in);
}
final Writer wr;
if (args.length > 1) {
wr = new FileWriter(new File(args[1]));
}
else {
wr = new OutputStreamWriter(System.out);
}
Preconditions.checkState(jp.nextToken() == JsonToken.START_ARRAY);
while (jp.nextToken() != JsonToken.END_ARRAY) {
final JsonNode jn = mapper.readTree(jp);
final JsonGenerator jg = jf.createJsonGenerator(wr);
mapper.writeTree(jg, jn);
wr.append("\n");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment