NAME

JSON::JsonModel - Perl Runtime for JSON Model

SYNOPSIS

For a generated script in File acme.pl:

acme.pl
  [--help] [--version] [--list]
  [--name] [--test] [--jsonl] [--time=TIME] [--report]
  value.json ...

For a generated module in File Acme.pm:

use JSON::MaybeXS;
use Acme;
check_model_init();
$json_value = ...;
$valid = check_model($json_value, "", undef);
check_model_free();

DESCRIPTION

This runtime is used by JSON Model generated scripts or modules to validate whether a JSON value conforms to a model. A model describes the expected JSON datastructure with a JSON syntax. It is a kind of type declaration for JSON values, with some features which go beyond the typical type system.

Use jmc, the JSON Model Compiler to generate a Perl script or module.

The reminder of this page describes the script behavior and available options. Look at the "SEE ALSO" section below for further reading.

OPTIONS

--help|-h

Show some help and exit.

--man|-m

Show full man page and exit.

--version|-v

Show version and exit.

--list|-l

List available named models and exit.

--name=NAME|-n NAME

Check values against this named model.

--test|-t

Assume test vector file format: JSON array of 3-tuples (expected result, model name, JSON value). Using null as expect means no expectation.

--jsonl

Assume JSON list format (one value per line).

--time=TIME|-T TIME

Run with performance loop, report average and standard deviation per file.

--report|-r vs --no-report

Report reason on rejections, or not.

ARGUMENTS

JSON files to consider.

Returns an error status on bad options or on validation expectation errors.

OUTPUT

For each file and possibly line/test in file, report PASS if validation succeeded (as expected), FAIL if failed (as expected), ERROR on unexpected result.

EXAMPLE

Generate a Perl script to validate JSON strings which contain a valid date:

echo '"$DATE"' | jmc -o date.pl

The generated script expect JSON file names arguments to validate their contents, with - standing for standard input:

echo '"2020-07-29"' | date.pl -  # PASS
echo '"2025-02-29"' | date.pl -  # FAIL - no Feb 29th in 2025
echo '[1, "array"]' | date.pl -  # FAIL - not even a string

VERSION

Version 2.0b3.

SUPPORT

You can find documentation for this module with the perldoc command:

perldoc JSON::JsonModel

Please report any bugs or feature requests to JSON Model Issues on GitHub.

LICENSE AND COPYRIGHT

The authors have dedicated the work to the Commons by waiving all of their rights to the work worldwide under copyright law and all related or neighboring legal rights the had in the work, to the extent allowable by law.

Works under CC0 do not require attribution, but it is polite to do so. When citing the work, you should not imply endorsement by the authors.

SEE ALSO

See JSON Model Tutorial for an introduction.

See JSON Model HOWTO for integrating models in a (Perl) project.

See more references on the JSON Model web site.