Options
All
  • Public
  • Public/Protected
  • All
Menu

json-schema-keyref

Index

Functions

lookup

  • Searches for a set of jsonpath queries.

    Parameters

    • queries: ISchemaDefinition

      identifier and jsonpath pairings to look up

    • document: Record<string, unknown>

      JSON document that will be searched

    Returns IQueryListing

    identifier and results pairings found in the document

    Example:

    var queries = [{"one": "$.a"}, {"two": "$.b"}];
    var document = {"a": "something", "b": "something else"};
    
    var result = lookup(queries, document);
    
    console.log(result);
    // {
    //   "one": [{"path": ["$", "a"], "value": "something"}],
    //   "two": [{"path": ["$", "b"], "value": "something else"}]
    // }
    

referenceCheck

  • Checks that all keyrefs have an associated key

    Parameters

    Returns IValidationResult

    validity status and any errors found

    Example:

    var keyrefs = [{"path": ["$", "some", "path"], "value": "example"}];
    var keys = [{"path": ["$", "some", "other", "path"], "value": "example"}];
    
    var result = referenceCheck(keyrefs, keys);
    
    console.log(result); //=> {"isValid": true, "errors": []}
    

validate

  • Validates a JSON document against a JSON schema with keyref and key constraints defined

    Parameters

    • document: Record<string, unknown>

      document to be validated

    • schema: IKeyKeyrefPair<ISchemaDefinition>

      schema with keyref and key groups defined

      Example:

      var document = {"a": "value", "b": "value"};
      var schema = {
        "keyrefs": {"identifier": "$.a"},
        "keys": {"identifier": "$.b"}
      };
      
      var result = validate(document, schema);
      
      console.log(result); //=> {"errors": [], "isValid": true}
      

    Returns IValidationResult

Generated using TypeDoc