XML technologies / JSON for XML professionals / Security, decisions and practice

JSON’s small syntax must not be confused with a small number of possible errors. Many problems arise only at boundaries: when using permissive parsers, transferring large numbers, rendering HTML or fetching external contexts. A sound publishing design addresses these boundaries explicitly.

Security does not reside in the file format alone

JSON should be read with a JSON parser, not executed as a program using eval. The standard describes a data format; evaluation as code is not a necessary property of that format. Nor does JSON automatically make an HTML string it contains trustworthy. [Q04]

The rich-text renderer in this package implements only approved node types. Text is treated as text, not as markup to fetch or execute. References are limited to local fragment targets. A production renderer supporting external links, images or embedded HTML needs additional rules for permitted protocols, targets and content.

The corresponding principle applies to XML: secure parser configuration and controlled handling of external resources remain necessary. The example rejects DOCTYPE declarations and disables external entity resolution. This is an input-profile decision for the example, not a judgment on XML’s general suitability.

JSON-LD processing may involve external contexts. In reproducible or isolated environments, contexts should be resolved in a controlled manner or defined locally. The example document therefore uses an embedded context, and the prepared PyLD expansion prohibits network retrieval. [Q34]

Embedding JSON correctly in HTML

A JSON string may be syntactically correct yet cause problems when inserted into HTML without checks. In a script element, the HTML parser first determines where the content ends. JSON escaping rules alone therefore do not provide a complete embedding strategy. [Q39]

The following JavaScript shows the additional handling of the less-than sign for a JSON data block. \u003c is a valid JSON escape sequence. A JavaScript-specific escape sequence such as \x3c would not be valid inside pure JSON.

const jsonText = JSON.stringify(book).replace(/</g, "\\u003c");
const markup = '<script type="application/ld+json">'
  + jsonText
  + '</script>';

This is a context-specific example, not a universal HTML sanitizer. Different rules apply to HTML attributes, URLs, visible text nodes and existing third-party HTML. Indiscriminately replacing quotation marks with HTML entities throughout the JSON data block is no substitute for correct serialization and context-appropriate embedding.

Decision guidance for XML teams

The following matrix offers recommendations for typical publishing tasks. It is deliberately not a ranking of formats. Each row is governed by the information requirements.

Task

Natural starting point

Rationale and limitations

Existing JATS, TEI, DITA or DocBook editorial workflow

Continue using the existing domain-specific XML

Document structure and existing rules are preserved; JSON views can be added

Catalog API for a web application

JSON defined by a contract

Objects and lists suit the interface; types, lists and null values must be specified

CMS with controlled content components

Documented component model, possibly JSON

Good application integration; portability depends on the model

Extensive mixed content with complex markup

Domain-specific XML or an equally carefully defined rich-text model

A string or a flat property list is insufficient

Linked metadata on web pages

JSON-LD from controlled sources

Vocabularies, identities and context are crucial, not just JSON syntax

RDF processing in an XML-oriented infrastructure

RDF/XML may still be suitable

JSON-LD and RDF/XML can carry the same graph; assess dataset requirements separately

Long-term maintenance and archiving

Documented model with sustainable tools

A file extension alone guarantees neither readability nor domain completeness

The key recommendation is therefore to describe the content, its rules and the required operations before choosing JSON or XML. You can then decide which format entails the least extra effort and the lowest risk of loss at each interface.

Running the example package

The package contains inputs, expected results, actual generated results, validation rules, transformation sources and a machine-readable test report. It is not an application connected to a production CMS. All CMS data consists of local model examples.

The core checks require Python and the listed libraries. Node.js and jq are also required for the corresponding language comparisons. The report lists the specific versions used in the test run.

python -m venv .venv
. .venv/bin/activate
python -m pip install -r requirements-core.txt
python scripts/run_all.py
python scripts/build_site.py
python -m http.server 8000 --bind 127.0.0.1

On Windows, activate the virtual environment with .venv\Scripts\Activate.ps1 in PowerShell. Then open the preview at http​://127.0.0.1:8000/preview/index.html. The interactive example page is at preview/lab.html. For JavaScript modules and local data requests, open the preview over HTTP rather than simply double-clicking a file: address.

The additional runtime paths are installed and checked separately:

python -m pip install -r requirements-extended.txt
python scripts/run_all.py --extended --require-all
python scripts/build_site.py
python scripts/browser_qa.py

--require-all is deliberately strict: a skipped runtime path does not count as a fully successful acceptance test. A missing tool must not be replaced by an invented result. In the initial version created here, the available core checks were actually run; the missing additional runtimes are marked as skipped in the accompanying report.

Short exercises with verifiable results

For the first exercise, remove one author from the list. The result must still contain an array with one object. For the second exercise, replace available with the string "true". The parser may read the record, but schema validation must reject it.

The third exercise changes a link target in mixed content. The structure may remain valid while the business rule reports an unknown section. The fourth exercise builds a JSON array with a null value between two book titles and compares position-preserving XQuery processing with careless unpacking and reconstruction.

For the fifth exercise, change the order of ordinary object properties. The JSON structural comparison should still succeed. Then change the order of an explicit JSON-LD @list array. The semantic comparison must detect this change. This demonstrates that equality always depends on a chosen model.

Conclusion: JSON complements XML expertise

For XML users, JSON is no reason to discard existing knowledge of modeling, validation and transformation. On the contrary, this knowledge is precisely what helps reveal the real architectural questions behind a concise syntax.

JSON excels at exchanging explicit objects, lists and simple values between applications. XML excels when a document-oriented node tree, mixed content, namespaces and existing domain vocabularies underpin the workflow. JSON-LD adds a semantic mapping that must not be confused with ordinary JSON keys. XSLT and XQuery remain usable in an architecture involving JSON, provided that the processor supports the required functions.

A sustainable publishing solution therefore does not arise from swapping brackets. It arises from documented models, controlled conversions, traceable tests and visible results.

back to top