Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serde_json prettifier #6

Open
dtolnay opened this issue Dec 28, 2016 · 0 comments
Open

serde_json prettifier #6

dtolnay opened this issue Dec 28, 2016 · 0 comments

Comments

@dtolnay
Copy link

dtolnay commented Dec 28, 2016

Not an issue with json_pretty but I thought you might be interested in comparing the same thing implemented with serde_json:

extern crate serde_json;
extern crate serde_transcode;

use std::io;

fn main() {
    let s = r#"{"description": "string for test", "id" : 123, "true" : true}"#;

    // A streaming JSON deserializer.
    let mut deserializer = serde_json::Deserializer::new(s.bytes().map(Ok));

    // A streaming pretty JSON serializer that writes to stdout.
    let mut serializer = serde_json::Serializer::pretty(io::stdout());

    // Efficiently process the input string while writing it in pretty form to stdout.
    serde_transcode::transcode(&mut deserializer, &mut serializer).unwrap();
}
{
  "description": "string for test",
  "id": 123,
  "true": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant