2026-12-01

JOP in Practice: Smart Configuration Files and the EKON 30 Demos

In the previous articles of this EKON 30 series, we introduced the JSON data model, its various representations, the native mORMot parser, and the motivation for our new jop tool.

A marmot operating machinery which turns source files into configuration data

Let's now have a look at some actual source files, in particular the DHCP-shaped configuration example from the presentation. We have also put the ten little terminal demos into the mORMot 2 trunk, so anyone can reproduce the conversions and look at the resulting files.

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

A marmot reviewing tests with an AI rubber duck

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

Source Code

The current mORMot 2 trunk:

JOP: Generating Better JSON Configuration

A marmot trying to cope with an accumulation of configuration files

Configuration files usually start simple. Then we add several services, a few deployment environments, some nested arrays of settings... and end up maintaining almost identical files, with very little indication of what actually differs between them.

A marmot trying to cope with an accumulation of configuration files

This was the main motivation for the new jop tool introduced at EKON 30. Its job is not to define yet another configuration format, but to generate ordinary configuration files from more maintainable sources. JSON is a good target. It need not be the only input.

Continue reading

JSON Processing in mORMot 2: SAX, UTF-8 and DOM

A marmot operating a mechanical structured-text parser

How much work is actually needed to convert JSON into JSON5 or Hjson? If we already have the text in memory, do we really need to allocate an object for every JSON value, then traverse the resulting tree to write it back?

A marmot operating a mechanical structured-text parser

Following our EKON 30 session about configuration files, let's have a look at the Object Pascal code behind the new jop tool. The interesting part is that the same mORMot 2 core can work either directly on the UTF-8 text, or on an in-memory document when its structure is needed.

Continue reading

Beyond INI and JSON: Human-Friendly Configuration Formats

A marmot surrounded by different representations of structured data

At EKON 30 in Düsseldorf, my session entitled Beyond INI & JSON: Smart Configuration Files was about a rather common problem: how to keep configuration files readable when the data they contain becomes less and less simple.

A marmot surrounded by different representations of structured data

Before introducing the new jop tool of our Open Source mORMot 2 framework, it may be worth looking at the formats themselves. There is something rather nice about JSON: its syntax may not be the best for human editing, but its data model is surprisingly useful.

Continue reading

2026-11-17

ZIP Encryption in mORMot 2

ZIP file compression (including Unicode and zip64 extension) has been supported by mORMot for a long time, with our own TZipRead and TZipWrite classes, optimized for both memory and file processing.
One missing feature was encryption.

This has now changed. Our latest mORMot 2 trunk supports the traditional PKWARE ZipCrypto algorithm, the WinZip AES-128/192/256 format (AE-1 and AE-2), and even the brand-new AES-256-GCM format (AE-3), introduced by WinZip just a few weeks ago.

All this is implemented in a new optional mormot.crypt.zip unit, without adding any external dependency.
The story behind this implementation is also worth sharing. It started with an AI-powered pull request, which we then reviewed, refactored, tested, optimized, and considerably extended.

Continue reading

2026-08-28

mORMot 2 HTTP Server: Memory Efficiency and Thread Smoothing

High-performance HTTP servers are often benchmarked primarily by their peak requests per second. For a REST server, however, peak throughput is only part of the story. A server also needs to remain responsive when requests have very different execution times: some may complete in a few microseconds, while others may spend milliseconds waiting for a database, a remote service, or some other slow operation.

The mORMot 2 asynchronous HTTP server was one of the fastest in the TFB benchmark. But it was designed as a scalable REST server. Our project has recently received two related improvements in this area: a closer look at its memory allocation behavior, and a refined thread smoothing mechanism for waking worker threads on POSIX systems.

Continue reading

2026-08-12

A New Native i18n Layer for mORMot 2

Internationalization (aka i18n) is now part of the mORMot 2 core with the new mormot.core.i18n unit, introduced by PR #510 - and deeply rewritten and completed, as always. The goal is not to create yet another translation format, but to provide a small, fast and framework-native i18n layer for both Delphi and Free Pascal.

The basic principle is deliberately simple: the original English text is the translation key. For example, "Hello" can be translated to "Bonjour". If a translation is missing, the original text remains available as the natural fallback. This keeps application code readable and makes the translation tables straightforward to maintain.

Continue reading

2026-08-07

A 2 GB/s XML Parser for Delphi and Free Pascal: SAX, Streaming and DOM Without the Usual Trade-offs

XML may no longer be fashionable, but it is still everywhere.

Scientific datasets, configuration files, industry standards, legacy systems, government data, document formats and countless integration interfaces continue to produce XML. And when XML documents become large, the choice of parser can make a surprisingly large difference.

For mORMot 2, we have recently written a new XML parser, TXmlParser, with a slightly different goal from the traditional XML libraries found in the Delphi and Free Pascal ecosystems. It started from an AI-driven pull request from zen010101, then it was fully rewritten by hand for performance and enhanced to support several API modes.

Instead of choosing between a low-level SAX parser and a convenient DOM parser, the same parser provides several levels of access:

  • a zero-allocation SAX/pull API;
  • a streaming/navigation API for selecting only the parts of the document that matter;
  • a hybrid SAX/DOM API, where selected subtrees can be materialized as TDocVariantData;
  • and a full XML-to-TDocVariant DOM representation, when that is what the application actually needs.

The interesting part is that the performance remains very high at all these levels.

Using the 24 MB nasa.xml reference document from the University of Washington XML repository, the raw parser reaches about 2.1 GB/s, while the full DOM conversion reaches about 424 MB/s. Selective streaming reaches about 1.6 GB/s, and once the DOM exists, traversing it through the new TDocVariantData.Product() enumerator reaches about 7 GB/s.

There is also an interesting memory optimization: enabling dvoInternNames reduces the complete DOM footprint from approximately 60 MB to 40 MB, with essentially no performance penalty.

The complete benchmark is shown below.

Continue reading

- page 1 of 53