1 unstable release

0.1.0 Nov 6, 2022

#1452 in Database interfaces

Download history 46/week @ 2023-12-04 70/week @ 2023-12-11 144/week @ 2023-12-18 52/week @ 2023-12-25 42/week @ 2024-01-01 82/week @ 2024-01-08 49/week @ 2024-01-15 39/week @ 2024-01-22 42/week @ 2024-01-29 43/week @ 2024-02-05 74/week @ 2024-02-12 88/week @ 2024-02-19 89/week @ 2024-02-26 83/week @ 2024-03-04 72/week @ 2024-03-11 81/week @ 2024-03-18

357 downloads per month
Used in 24 crates (3 directly)

MIT license

23KB
348 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

~7.5MB
~238K SLoC