A Rust library and command-line tools to validate the syntax of CityJSON objects (CityJSON + CityJSONSeq).
It validates against the CityJSON schemas and includes additional validation functions that cannot be expressed with JSON Schemas.
The following error checks are performed:
- JSON syntax: is it a valid JSON object?
- CityJSON schemas: validation against the schemas (CityJSON v1.0 + v1.1 + v2.0)
- Extension schemas: validate against the extra schemas if there's an Extension (those are automatically fetched from a URL)
- parents_children_consistency: if a City Object references another in its
"children", this ensures that the child exists and that the child has the parent in its"parents" - wrong_vertex_index: checks if all vertex indices exist in the list of vertices
- semantics_array: checks if the arrays for the semantics in the geometries have the same shape as that of the geometry and if the values are consistent
- textures: checks if the texture arrays are coherent (if the referenced vertices exist and if the texture exists)
- materials: checks if the arrays for the materials are coherent with the geometry objects and if the material exists
It also verifies the following; these are not errors but warnings since the file is still considered valid and usable. However, they can make the file larger, and some parsers might not understand all the properties:
- extra_root_properties: if a CityJSON file contains extra root properties, these should be documented in an Extension. If not, this warning is returned
- duplicate_vertices: duplicated vertices in
"vertices"are allowed, but they take up space and reduce the explicit topological relationships in the file. If found, thecjiotool'scleanoperator can fix this automatically - unused_vertices: vertices that are not referenced in the file take up extra space. If found, the
cjiotool'scleanoperator can fix this automatically
cjval is a Rust library and includes two command-line binaries:
cjvalto validate a CityJSON file or a CityJSONSeq stream (it downloads Extensions automatically if the file contains any)cjvalextto validate a CityJSON Extension file
- install the Rust compiler
cargo install cjval --features build-binary
- install the Rust compiler
git clone https://github.com/cityjson/cjval.gitcargo build --release --features build-binary(this will ensure the binaries are compiled too)./target/release/cjval myfile.json
The code is used at https://validator.cityjson.org, where it is compiled as WebAssembly (WASM code here) with a simple GUI.
The CityJSON schemas are packaged with the binary, so it suffices to:
cjval myfile.city.json --verbose(the latest schemas of a X.Y version will be automatically fetched)
--verbose is used to get a detailed report per error check.
If the file contains one or more Extensions, eg:
{
"type": "CityJSON",
"version": "2.0",
"extensions":
{
"Potato":
{
"url": "https://www.cityjson.org/extensions/potato.ext.json",
"version": "1.0"
}
}
... then cjval will download the Extension schema files automatically.
If instead you want to use your own local Extension schema(s), you can pass them as arguments with the -e flag to overwrite the automatic download:
cjval myfile.city.json -e ./myextensions/generic.ext.jsonTo validate a stream of CityJSONFeature, you need to pipe the file to cjval:
cat mystream.city.jsonl | cjval --verboseAlternatively, you can use cjseq to generate the stream from a CityJSON file:
cjseq cat -f myfile.city.json | cjval --verboseYou'll get a short report per line (which is one CityJSON followed by several CityJSONFeature).
--verbose is used to get a detailed report per line; if not used, only lines with errors are reported.
- @hugoledoux
- @josfeenstra (started the project for an MSc Geomatics course at TU Delft, original code)