5 releases (3 breaking)

0.4.0 Nov 24, 2021
0.3.0 Nov 18, 2021
0.2.0 Nov 16, 2021
0.1.1 Nov 11, 2021
0.1.0 Nov 11, 2021

#2020 in Database interfaces

Download history 44/week @ 2024-01-08 7/week @ 2024-01-15 86/week @ 2024-01-22 24/week @ 2024-01-29 71/week @ 2024-02-05 65/week @ 2024-02-12 58/week @ 2024-02-19 59/week @ 2024-02-26 23/week @ 2024-03-04 25/week @ 2024-03-11 31/week @ 2024-03-18 20/week @ 2024-03-25 39/week @ 2024-04-01 35/week @ 2024-04-08 38/week @ 2024-04-15 92/week @ 2024-04-22

207 downloads per month
Used in 2 crates (via libflatterer)

MIT license

17KB
233 lines

jsonref dereferences JSONSchema $ref attributes and creates a new dereferenced schema.

Dereferencing is normally done by a JSONSchema validator in the process of validation, but it is sometimes useful to do this independent of the validator for tasks like:

  • Analysing a schema programatically to see what field there are.
  • Programatically modifying a schema.
  • Passing to tools that create fake JSON data from the schema.
  • Passing the schema to form generation tools.

Example:

use serde_json::json;
use jsonref::JsonRef;

let mut simple_example = json!(
          {"properties": {"prop1": {"title": "name"},
                          "prop2": {"$ref": "#/properties/prop1"}}
          }
       );

let mut jsonref = JsonRef::new();

jsonref.deref_value(&mut simple_example).unwrap();

let dereffed_expected = json!(
    {"properties": 
        {"prop1": {"title": "name"},
         "prop2": {"title": "name"}}
    }
);
assert_eq!(simple_example, dereffed_expected)

Note: If the JSONSchema has recursive $ref only the first recursion will happen. This is to stop an infinate loop.

Dependencies

~7MB
~224K SLoC