Skip to content

Instantly share code, notes, and snippets.

@heyimalex
Created November 23, 2016 19:28
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 heyimalex/cf58da737edd59aea6ecc5deb99b85be to your computer and use it in GitHub Desktop.
Save heyimalex/cf58da737edd59aea6ecc5deb99b85be to your computer and use it in GitHub Desktop.
Streaming json pretty printer
extern crate rustc_serialize;
use std::io;
use rustc_serialize::json::Json;
fn main() {
loop {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let raw = input.trim();
if raw.len() == 0 {
continue
}
match Json::from_str(raw) {
Ok(data) => println!("{}\n", data.pretty()),
Err(_) => println!("\nERROR PARSING LINE:\n{}\n", raw),
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment