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

RON -> JSON converter #45

Closed
ozkriff opened this issue Aug 9, 2017 · 1 comment
Closed

RON -> JSON converter #45

ozkriff opened this issue Aug 9, 2017 · 1 comment

Comments

@ozkriff
Copy link

ozkriff commented Aug 9, 2017

It should be possible to write an automatic RON->JSON converter for cases when you have a .ron file and an app that only reads .json files.

Initial discussion on gitter: https://gitter.im/ron-rs/ron?at=598b80f551915d962af79f5d

@dtolnay
Copy link

dtolnay commented Aug 10, 2017

Once RON is self-describing (#48), this is a matter of using serde-transcode.

extern crate ron;
extern crate serde_json;
extern crate serde_transcode;

fn main() {
    let data = r#"
        Scene( // class name is optional
            materials: { // this is a map
                "metal": (
                    reflectivity: 1.0,
                ),
                "plastic": (
                    reflectivity: 0.5,
                ),
            },
            entities: [ // this is an array
                (
                    name: "hero",
                    material: "metal",
                ),
                (
                    name: "monster",
                    material: "plastic",
                ),
            ],
        )
        "#;

    let mut de = ron::de::Deserializer::from_str(data);
    let mut ser = serde_json::Serializer::pretty(std::io::stdout());
    serde_transcode::transcode(&mut de, &mut ser).unwrap();
}

bors bot added a commit that referenced this issue Sep 21, 2017
53: Add Value and implement deserialize_any r=kvark a=torkleyy

Fixes #45
Fixes #48
@bors bors bot closed this as completed in #53 Sep 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants