-
Notifications
You must be signed in to change notification settings - Fork 52
Add JSON schema #1426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
franzpoeschel
wants to merge
19
commits into
openPMD:dev
Choose a base branch
from
franzpoeschel:json-schema
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add JSON schema #1426
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1c79dd0
Add JSON schema for openPMD
franzpoeschel a9d287e
Add convert-json-toml tool
franzpoeschel a201de6
Add script for checking openPMD file against the schema
franzpoeschel 643433d
Don't use spaces in SerialIOTest attribute names
franzpoeschel 87ab3d8
Fix bugs detected by this verifier
franzpoeschel 911ee98
Add GitHub workflow
franzpoeschel f571275
Shorthand attributes
franzpoeschel 0a7babd
Add dataset template mode
franzpoeschel 4e4c2fc
Fix path
franzpoeschel 7664491
Fix reading from stdin
franzpoeschel fc7c5d7
toml11 4.0 compatibility
franzpoeschel ddb8498
Only check for existing Iterations in writeOnly mode
franzpoeschel 50adde9
Some additions to schema
franzpoeschel d438300
Remove deprecated jsonschema.validators.RefResolver
franzpoeschel e04a258
Use most recent version of jsonschema
franzpoeschel 86d7703
Allow empty variable-based series
franzpoeschel 204d3a4
Use if-then-else for better-steered parsing
franzpoeschel 8507841
hmm
franzpoeschel 4193a3c
Remove json cfg after test
franzpoeschel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
convert := openpmd-convert-json-toml | ||
|
||
json_files = attribute_defs.json attributes.json dataset_defs.json iteration.json mesh.json mesh_record_component.json particle_patches.json particle_species.json patch_record.json record.json record_component.json series.json | ||
|
||
.PHONY: all | ||
all: $(json_files) | ||
|
||
# The target file should only be created if the conversion succeeded | ||
$(json_files): %.json: %.toml | ||
$(convert) @$^ > [email protected] | ||
mv [email protected] $@ | ||
|
||
.PHONY: clean | ||
clean: | ||
for file in $(json_files); do rm -f "$$file" "$$file.tmp"; done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# JSON Validation | ||
|
||
This folder contains a JSON schema for validation of openPMD files written as `.json` files. | ||
|
||
## Usage | ||
|
||
### Generating the JSON schema | ||
|
||
For improved readability, maintainability and documentation purposes, the JSON schema is written in `.toml` format and needs to be "compiled" to `.json` files first before usage. | ||
To do this, the openPMD-api installs a tool named `openpmd-convert-json-toml` which can be used to convert between JSON and TOML files in both directions, e.g.: | ||
|
||
```bash | ||
openpmd_convert-json-toml @series.toml > series.json | ||
``` | ||
|
||
A `Makefile` is provided in this folder to simplify the application of this conversion tool. | ||
|
||
### Verifying a file against the JSON schema | ||
|
||
In theory, the JSON schema should be applicable by any JSON validator. This JSON schema is written in terms of multiple files however, and most validators require special care to properly set up the links between the single files. A Python script `check.py` is provided in this folder which sets up the [Python jsonschema](https://python-jsonschema.readthedocs.io) library and verifies a file against it, e.g.: | ||
|
||
```bash | ||
./check.py path/to/my/dataset.json | ||
``` | ||
|
||
For further usage notes check the documentation of the script itself `./check.py --help`. | ||
|
||
## Caveats | ||
|
||
The openPMD standard is not entirely expressible in terms of a JSON schema: | ||
|
||
* Many semantic dependencies, e.g. that the `position/x` and `position/y` vector of a particle species be of the same size, or that the `axisLabels` have the same dimensionality as the dataset itself, will go unchecked. | ||
* The `meshesPath` is assumed to be `meshes/` and the `particlesPath` is assumed to be `particles/`. This dependency cannot be expressed. | ||
|
||
While a large part of the openPMD standard can indeed be verified by checking against a JSON schema, the standard is generally large enough to make this approach come to its limits. Verification of a JSON schema is similar to the use of a naive recursive-descent parser. Error messages will often be unexpectedly verbose and not very informative. | ||
A challenge for the JSON validator are disjunctive statements such as "A Record is either a scalar Record Component or a vector of non-scalar Record Components". If there is even a tiny mistake somewhere down in the hierarchy, the entire disjunctive branch will fail evaluating. | ||
|
||
The layout of attributes is assumed to be that which is created by the JSON backend of the openPMD-api, e.g.: | ||
|
||
```json | ||
"meshesPath": { | ||
"datatype": "STRING", | ||
"value": "meshes/" | ||
} | ||
``` | ||
|
||
Support for an abbreviated notation such as `"meshesPath": "meshes/"` is currently not (yet) available. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we able to patch this in
check.py
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not very easily. The JSON schema is on the file system and the single .json files refer to each other by their file names. Changing this would require (1) traversing the entire JSON schema and overriding the meshes path, the particles path and the references and (2) somehow setting up python-jsonschema to cross-reference in-memory schemas which I don't even know if it supports that, both at runtime of
check.py
.