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

#2570 in Database interfaces

Download history 78/week @ 2024-07-19 81/week @ 2024-07-26 35/week @ 2024-08-02 141/week @ 2024-08-09 152/week @ 2024-08-16 64/week @ 2024-08-23 75/week @ 2024-08-30 96/week @ 2024-09-06 99/week @ 2024-09-13 199/week @ 2024-09-20 85/week @ 2024-09-27 199/week @ 2024-10-04 224/week @ 2024-10-11 1885/week @ 2024-10-18 2035/week @ 2024-10-25 1830/week @ 2024-11-01

6,071 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

~8.5MB
~223K SLoC