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

#2597 in Database interfaces

Download history 2926/week @ 2024-11-16 1283/week @ 2024-11-23 1905/week @ 2024-11-30 1930/week @ 2024-12-07 2377/week @ 2024-12-14 844/week @ 2024-12-21 836/week @ 2024-12-28 1864/week @ 2025-01-04 1656/week @ 2025-01-11 1501/week @ 2025-01-18 2142/week @ 2025-01-25 3687/week @ 2025-02-01 3083/week @ 2025-02-08 2294/week @ 2025-02-15 2606/week @ 2025-02-22 2953/week @ 2025-03-01

11,609 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

~8MB
~201K SLoC