std/data/json/schema/model

Standard Library documentation

JSON value projection helpers.

Module

Name
std/data/json/schema/model
Area
Standard Library
Source
modules/std/data/json/schema/model.zzm

NAME

std/data/json/schema/model - JSON value projection helpers.

SYNOPSIS

  from std/data/json/schema/model import
    jschema_is_object,
    jschema_object_get,
    jschema_type_name;

  if ( jschema_is_object(value) ) {
    say( jschema_object_get( value, "title", "(untitled)" ) );
  }

  say( jschema_type_name(value) );

IMPLEMENTATION SUPPORT

This Pure Zuzu module is supported by all implementations of ZuzuScript.

DESCRIPTION

This module adapts native Zuzu collection types to the JSON data model used by the JSON Schema validator. It is mostly an implementation helper, but its functions are exported so related schema tools can share the same treatment of objects, arrays, and pointer locations.

Dict and PairList are object-like. PairList preserves duplicate keys through jschema_object_get_all and jschema_object_entries. Array is ordered array-like. Set and Bag are unordered array-like; they can be used for array keywords where order does not matter.

EXPORTS

Functions

  • jschema_is_object( value )

    Returns true for Dict and PairList.

  • jschema_is_ordered_array( value )

    Returns true for Array.

  • jschema_is_unordered_array( value )

    Returns true for Set and Bag.

  • jschema_is_arrayish( value )

    Returns true for ordered and unordered array-like values.

  • jschema_type_name( value )

    Returns the JSON Schema type name for value: null, boolean, number, string, array, object, or unknown.

  • jschema_type_matches( value, expected )

    Returns true when value matches the JSON Schema type named by expected. integer is accepted for numbers with no fractional part.

  • jschema_object_has( object, key )

    Returns true when an object-like value contains key.

  • jschema_object_get( object, key, fallback := null )

    Returns the value for key, or fallback when it is missing.

  • jschema_object_get_all( object, key )

    Returns all values for key. For Dict, the result has either one value or none. For PairList, duplicate keys are preserved.

  • jschema_object_keys( object )

    Returns object keys, preserving the underlying collection's key behaviour.

  • jschema_object_unique_keys( object )

    Returns object keys with duplicates removed.

  • jschema_object_entries( object )

    Returns an array of [ key, value ] pairs.

  • jschema_array_items( value )

    Returns the array items for an array-like value. Unordered collections are converted with to_Array().

  • jschema_array_length( value )

    Returns the length of an array-like value, or zero for other values.

  • jschema_pointer_escape( token )

    Escapes a JSON Pointer token by replacing ~ and /.

  • jschema_pointer_join( base, step )

    Appends step to a JSON Pointer path.

  • jschema_deep_equal( left, right )

    Compares two values using ZuzuScript equality. The validator uses this for const, enum, and uniqueness checks.

COPYRIGHT AND LICENCE

std/data/json/schema/model is copyright Toby Inkster.

It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.