Structured data · Core reference
JSON data.
@json binds immutable JSON under a page-scoped name. Data may come from a project file or an inline body, and either form can be validated by a schema file or an earlier named JSON binding.
The binding is always the first argument. This keeps all six forms visually consistent and makes inline JSON a natural extension of file-backed JSON.
The six forms
| Source | Without schema | Schema path | Named schema |
|---|---|---|---|
| File | @json(name, path) | @json(name, schema-path, path) | @json(name, schema-name, path) |
| Inline | @json(name){...} | @json(name, schema-path){...} | @json(name, schema-name){...} |
@json(site, 'data/site.json')
@json(product, 'schemas/product.schema.json', 'data/product.json')
@json(product_schema){
{"type":"object","required":["name"]}
}
@json(feature, product_schema){
{"name":"Markup++ in Nift"}
} Inline bodies are evaluated by Nift's template language before JSON parsing, so existing values can supply scalar content. File and schema paths also support single-pass $[...] interpolation. Binding names and named-schema references remain static identifiers.
@json(selector, 'data/selector.json')
@json(selected,
"schemas/$[selector.schema].json",
"data/$[selector.dataset].json") Access values
@json(site, 'data/site.json')
<h1>$[site.name]</h1>
<a href="$[site.navigation[1].url]">
$[site.navigation[1].title]
</a> Objects use .member; arrays use zero-based [index]. Strings, numbers, booleans and null render directly. Select a member or element before rendering an object or array.
Validate before rendering
A schema path is loaded as project data. A schema name refers to an earlier JSON binding, which is useful for reusable inline schemas. In the schema position a bare identifier is a schema binding name and must already exist; a quoted string is a schema path. A missing bare schema name is a build error and never falls back to a same-named file. Invalid data fails the build before the new binding becomes visible.
JSON Schema validation documents the supported Draft 2020-12-compatible subset, local $ref, errors and incremental behavior.
Files are dependencies
Nift records every loaded JSON data file and schema file automatically. Changes therefore invalidate affected outputs in modified, hash and hybrid modes. Parsed files are cached as immutable build-wide documents while each binding remains local to its page parser.
Scope and failures
Names use identifier-style letters, digits and underscores, cannot collide with built-ins or project contracts, and cannot be rebound in the same scope. Malformed JSON, missing or escaping paths, schema failures, missing members and invalid indices produce source-located build errors.
@json(data, 'data/articles.json')
@for(article : data.articles){
@if(article.published){
<h2>$[article.title]</h2>
}
}