Configuration
Validate a config
Check a config before loading the map. Validation errors identify the affected setting by its JSON path. This page uses the viewer’s validator and explains where else validation can run.
Paste a config
This page runs map0’s validateConfig. Errors prevent the map from loading.
Warnings, such as unknown keys, allow it to load while drawing attention to settings that
may need checking.
Inheritance: the viewer resolves extends before validation,
so a child config may inherit its basemaps. This page validates the pasted document as it
is.
Every place a config is checked
In your editor, as you type
Add a $schema entry to associate the config with its JSON Schema. Editors
such as VS Code and JetBrains can use it for completion, hover documentation and
validation:
{
"$schema": "https://map0.net/schema/v1.json",
"version": 1,
"basemaps": [{ "type": "style", "url": "…" }]
}In CI, before it ships
Use a JSON Schema validator in your build pipeline or when saving a config in the CMS:
npx ajv-cli validate -s node_modules/map0-viewer/schema/v1.json -d my-map.map0.json
check-jsonschema provides a Python option. The schema checks keys, types,
value ranges and required fields.
In your own code
The npm package exports the validator through its SSR entry. It can run in Node without a DOM, for example to check a config before saving it:
import { validateConfig } from "map0-viewer/ssr"; const { valid, errors, warnings } = validateConfig(config); // errors: [{ path: "$.layers[0].url", message: 'a "wms" layer needs a "url"' }]
In the viewer, always
The viewer validates again before rendering and displays errors in place. Its checks
include URL rules, unique IDs across basemaps and layers, and relationships between
fields, such as a colour ramp’s min being less than its max.
$.basemaps at least one basemap is required, e.g. { "type": "style", "url": "…" }
$.layers[2].url a "wms" layer needs a "url"
$.layers[2].layers a "wms" layer needs "layers" (WMS LAYERS parameter)The schema, published
The same schema is available at three locations:
-
https://map0.net/schema/v1.json: follows the latest release, for the config’s$schemaentry -
https://cdn.jsdelivr.net/npm/map0-viewer@0.3.0/schema/v1.json: fixed to one package release -
node_modules/map0-viewer/schema/v1.json: available locally with the installed package
The filename refers to the config format version ("version": 1). Descriptions
in the schema provide editor documentation. Tests compare its keys and enums with the
runtime validator.