Skip to content

NIAGADS/metadata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Schemas for JSON Validation

Developed in support of collecting and validating metadata but can be used for validating JSON configuration files for analysis pipelines as well.

Requirements for NIAGADS JSON Schemas

Projects should use the Draft7 specification: https://json-schema.org/draft-07/json-schema-release-notes

$schema should be set to http://json-schema.org/draft-07/schema# and contain at least the following:

    {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "type": "object",
        "title": "",
        "description": "",
        "properties": {},
        "requried": []
    }

Python projects should use the NIAGADS-pylib to leverage our customized Draft7Validator as follows:

from niagads.json_validator.core import JSONValidator

schemaFile = "schema.json" # file defining the JSON schema against which the JSON is to be validated
jsonObj = {"id": 2, ...} # JSON object to be validated

validator = JSONValidator(jsonObj, schemaFile)
validator.run() # returns True if jsonObj passes validation; a list of ValidationErrors otherwise

This validator extends the Draft7 specification to support the following field formats:

  • DOI (doi)
  • PUBMED ID (pubmed_id)
  • md5sum (md5sum)

Developer notes

Missing Data

Required Fields

The required tag of the schema indicates fields (columns in the tab-delimited text version) that must be present in the file, even in all values for the field are left empty.

If a field (property) is not required the schema/metadata file will pass validation even if the field/column is missing.

NULL (empty) values

Whether a field is required or not, if you want to allow NULL/empty values in the JSON config or metadata worksheet, you must set the type of the field (property) to null. For example in the following schema snippet:

{
    "properties": {
        "address": {
            "type": ["string", "null"]
        }
    },
    "required":["address"]
}

The address field (property) is required (must be present) and the value should be a string, but nulls (empty cells/missing data) are allowed.

Useful Documentation & Tools to help write JSON Schemas

Introduction

conditionals

built-in formats for validation

Online validator

About

metadata templates and validators

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •