Sharing Definitions between DHCP Scopes
In our sixth demo, a small definition file is shared by two DHCP scopes. Here is the actual common.def file:
$$ # Local shared definitions for two scopes lease = 3600 dns = 192.168.50.1 gateway = 192.168.50.1 $$
And here is a shortened version of dhcp.hjson, retaining both scopes and the main pools:
$$
include common.def
$$
{
"file-name": "dhcp.leases",
"scope": [{
"subnet-mask": "192.168.50.1/24",
"default-gateway": $(gateway),
"dns-servers": $(dns),
"lease-time-seconds": $(lease),
"main": {"min":"192.168.50.20", "max":"192.168.50.220"}
},{
"subnet-mask": "192.168.60.1/24",
"default-gateway": "192.168.60.1",
"dns-servers": $(dns),
"lease-time-seconds": $(lease),
"main": {"min":"192.168.60.20", "max":"192.168.60.220"}
}]
}
To generate the JSON file:
jop convert dhcp.hjson dhcp.json --include-root . --compact --validate-json
Change the DNS address or the lease duration in common.def and regenerate. Each scope in the resulting JSON contains the expanded address and the numeric lease duration. The second scope retains its own gateway and pool settings. The existing server doesn't have to understand includes or variables.
The 06-dhcp-smart demo also contains a static reservation and converts the generated JSON to YAML, then back to JSON for comparison. It is a teaching fixture, not a ready-to-deploy DHCP configuration.
Definitions, Conditions and Plain Text
The 05-preprocess fixture uses typed values, explicit string interpolation and conditionals. It passes --define mode=preview from the command line, but the source defines mode again, ending with production. The last definition wins.
For missing definitions, the preprocessor also supports a fallback. The following small example uses the same syntax as the native regression tests:
$$ name = world $$ Hello $(name)! Environment: $(deployment|development)
Save it as message.jop and generate text:
jop convert message.jop message.txt --define deployment=production
The output is plain text:
Hello world! Environment: production
There is no JSON parser involved in this text-to-text case. In the native code, TextPreprocessToWriter() shares the preprocessor machinery with JsonPreprocessToWriter().
The .jop extension selects text input by default. For JSON-shaped content stored with this extension, explicitly select e.g. --from hjson.
With plain text you can also use literal sections delimited by three dollar signs. The TTestCoreJop.Text regression test checks that placeholders within such sections remain untouched. Include and insert are available when an include root is supplied; insert does not expand the inserted bytes.
YAML, XML and CSV input preprocessing is opt-in. The 07-input-preprocess demo makes this distinction explicit:
jop convert template.yaml literal.json --compact --define name=Alice jop convert template.yaml expanded.json --compact --define name=Alice --preprocess-input
Without the option, the placeholder in the YAML input stays literal. With it, the source text is expanded before parsing. The XML example in the same folder behaves similarly. Be sure that the substituted text is valid in the source format. No second expansion is done on the converted data.
For normal conversion of external data, --no-expand bypasses the preprocessor altogether. --no-namespaces disables external namespace lookup while retaining local definitions. Include access needs an explicit --include-root, with path checks and bounded nesting. Avoid enabling absolute include paths unless needed, and review template input before processing it.
The Other Commands, and Some Error Cases
Conversion is the default when supplying two filenames. Formats are inferred from extensions, unless --from or --to is supplied. Filenames come before switches. The command-specific help describes the available options:
jop --help jop convert --help jop batch --help
The generate command produces pseudo-random JSON, with a reproducible seed if requested. This is useful for tests and benchmarks:
jop generate sample.json --depth 3 --items 5 --seed 42 jop convert sample.json sample.pretty.json --no-expand jop compare sample.json sample.pretty.json
Note that compare compares the compact JSON representation returned by our native JsonReformat(). It is not deep semantic equality: property order still matters, as can some number spellings. No extra validation or macro expansion is performed. Exit codes are 0 for success or equality, 1 for different documents, and 2 for a usage or processing error.
For a whole directory of configurations:
jop batch "input/*.json" output --to yaml --recursive --dry-run jop batch "input/*.json" output --to yaml --recursive --stats
Quote the mask so JOP expands it, rather than your shell. Recursive batch processing preserves relative paths and checks destination collisions before writing. Dry runs plan processing without reading file contents or writing output. For individual file conversions, the destination is replaced only after successful processing, so an existing output survives a conversion failure.
--validate-json requests the native structural check, not full RFC 8259 or application-specific schema validation. --validate-utf8 is also available.
Calling the Pascal API
Of course, there is no need to spawn an external process from Delphi or Free Pascal. The mormot.tools.jop unit exposes the same processing functions:
var
source, output: RawUtf8;
options: TJopOptions;
begin
source := RawUtf8FromFile('config.hjson');
options := JopOptions(jfHjson, jfJson, [jofCompact]);
if JopProcess(source, options, output) = jeSuccess then
FileFromString(output, 'config.json');
end;
The in-memory input buffer has to be private and writable, and is consumed by the call (see the second article in this series). The error-returning overload allows us to check TJopError and obtain optional contextual diagnostic information. Writer, stream, CSV collection, single-file and batch entry points are also available. Caller-owned writers and streams may contain partial output on failure: discard it rather than using it as a valid document.
When working with nested arrays and CSV, JopProcessToCsv() returns the whole collection of related tables in a TTextPairs. This is preferable to trying to squeeze the document into one arbitrary CSV table. Or use one of the two Markdown outputs from the command line.
Run the EKON 30 Demos
The command-line executable may be built from jop.dpr with Delphi, or jop.lpi in Lazarus with the mORMot package installed. With a native JOP executable and a POSIX shell, go to the following folder (adapt the symbolic link to wherever you built the executable):
cd src/tools/jop/demo ln -s /absolute/path/to/jop jop ./jop --help ./06-dhcp-smart/run.sh
The demos display their source files, the actual command, its output, and check some expected results. Each has a README with more details. Here is the complete list:
- 01-generate-compare - seeded random JSON, reformatting and normalized compact comparison;
- 02-json-flavors - the same Hjson document converted to JSON, JSON5, JSONC and MorML;
- 03-sax-vs-dom - JSON-family conversion versus document-aware YAML/CSV exports, with statistics;
- 04-xml-attributes - attributes, repeated elements, element text, XML scalar strings and YAML output;
- 05-preprocess - definitions, interpolation, conditionals and command-line defaults;
- 06-dhcp-smart - shared definitions and two DHCP scopes, with a JSON/YAML round trip;
- 07-input-preprocess - opt-in preprocessing of YAML and XML before parsing;
- 08-csv-markdown - CSV import preserving string values, relational export and both Markdown representations;
- 09-batch - recursive conversion, dry run and relative output paths;
- 10-error-cases - exit codes, order-sensitive comparison, and preservation of the destination upon failed XML conversion.
To run them all from the demo folder:
./run-all.sh ./verify.sh ./clean.sh
The optional verification script runs the demonstrations and checks their output with Python 3 (standard library only). The cleanup script removes generated files, not the source fixtures.
And the Actual Regression Tests

As I mentioned at EKON, AI was useful in exploring some alternatives and proposing tests, but the Pascal implementation needed a careful human review. An AI rubber duck still needs a maintainer. The TTestCoreJop regression tests exercise the reusable processing API itself, including buffer ownership, format conversion, preprocessing, validation, file replacement, batch collisions and error cases.
This is probably the most important part of the implementation: the tests make the actual behavior explicit, including what the tool does not promise.
The point of JOP is not another configuration religion. Write and maintain the configuration in a form which suits the people editing it, generate the data once, then let the application do its job. A few useful additions to our mORMot toolbox, which can also be used without the rest of the framework.
Beyond INI & JSON - The EKON 30 Series
- 1. Human-friendly configuration formats
- 2. The native JSON parser: SAX, UTF-8 and DOM
- 3. JOP: generating better JSON configuration
- 4. JOP in practice: smart configuration files and demos (this article)
Source Code
The current mORMot 2 trunk:





