d4t4

Crates.iod4t4
lib.rsd4t4
version0.2.2
sourcesrc
created_at2020-05-30 11:06:34.265714
updated_at2020-05-30 14:12:43.732293
descriptionA JSON superset
homepage
repositoryhttps://github.com/mathiversen/d4t4
max_upload_size
id247658
size35,069
Mathias (mathiversen)

documentation

README

github

D4t4

WIP - work in progress, use at your own risk

A JSON superset

Features

  • JSON-compatible
  • Objects & arrays may have trailing comma
  • Object keys may not need quotes
  • Single & multiline comments are allowed
  • Strings may use double and/or single quotes
  • Values can be referenced from other parts of the object tree

Example

    use d4t4::parse;

    fn main() {
        let data = r#"{
           /*
               Look how nice, we can separate re-useable data!
           */
           padding: {
               s: '1px',
               m: '2px',
               l: '3px', // note: triling comma
           },
           color: {
               red: '#fed7d7',
               green: '#c6f6d5',
               blue: '#bee3f8', # note: found another one!
           },
           objects: [
               {
                   border: "1px solid &{color.red}",
                   padding: "&{padding.s}",
               },
               {
                   border: "1px solid &{color.green}",
                   padding: "&{padding.m}",
               },
               {
                   border: "1px solid &{color.blue}",
                   padding: "&{padding.l}",
               },
           ]
        }"#;

        let json = parse(data).ok().unwrap();
        assert_eq!(json["objects"][0]["padding"], "1px");
        assert_eq!(json["objects"][1]["padding"], "2px");
        assert_eq!(json["objects"][2]["padding"], "3px");
    }

Parse json:

    use d4t4::parse;

    fn main() {
        let json = r#"{
            "number": 100,
            "null": null,
            "true": true,
            "object": {},
            "array": [1,2,3],
            "unicode": "\u1234",
            "string": "check out the tests directory if you want to see more",
        }"#;

        assert!(parse(json).is_ok());
    }

Contributions

I would love to get some feedback if you find my little project useful. Please feel free to highlight issues with my code or submit a PR in case you want to improve it. Note that the goal so far hasn't been performance, rather on functionality and api.

Commit count: 34

cargo fmt