1 unstable release

0.1.0 Nov 6, 2022

#1689 in Database interfaces

Download history 63/week @ 2024-07-22 56/week @ 2024-07-29 79/week @ 2024-08-05 66/week @ 2024-08-12 57/week @ 2024-08-19 111/week @ 2024-08-26 52/week @ 2024-09-02 71/week @ 2024-09-09 63/week @ 2024-09-16 80/week @ 2024-09-23 51/week @ 2024-09-30 1/week @ 2024-10-07 48/week @ 2024-10-14 55/week @ 2024-10-21 47/week @ 2024-10-28 65/week @ 2024-11-04

215 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

~8MB
~201K SLoC