{"id":6690,"library":"json-spec","title":"JSON Spec","description":"JSON Spec is a Python library that provides implementations for several JSON specifications, including JSON Schema (specifically Draft 03 and Draft 04), JSON Pointer, and JSON Reference. The current version is 0.12.0, with the last release approximately two years ago. While not actively updated to support the latest JSON Schema drafts, it remains a functional tool for applications requiring adherence to its supported specifications.","status":"maintenance","version":"0.12.0","language":"en","source_language":"en","source_url":"https://github.com/johnnoone/json-spec","tags":["JSON Schema","JSON Pointer","JSON Reference","validation","schema","data validation","json"],"install":[{"cmd":"pip install json-spec","lang":"bash","label":"Core library"},{"cmd":"pip install json-spec[cli]","lang":"bash","label":"With CLI tools (e.g., colorated messages)"},{"cmd":"pip install json-spec[ip]","lang":"bash","label":"With IP format validation for JSON Schema"}],"dependencies":[{"reason":"This library implements *some* JSON specs, but the more popular `jsonschema` library often handles more modern JSON Schema drafts. Users might confuse them or need both.","package":"jsonschema","optional":true}],"imports":[{"symbol":"load","correct":"from jsonspec.validators import load"},{"note":"Common alias for JSON Pointer operations","symbol":"json_pointer","correct":"import jsonspec.pointer as json_pointer"},{"note":"Common alias for JSON Reference operations","symbol":"json_reference","correct":"import jsonspec.reference as json_reference"}],"quickstart":{"code":"from jsonspec.validators import load\nfrom jsonspec.pointer import Pointer\n\n# Define a JSON Schema (defaults to Draft 04)\nschema = {\n    'title': 'Example Schema',\n    'type': 'object',\n    'properties': {\n        'name': {'type': 'string'},\n        'age': {'type': 'integer', 'minimum': 0}\n    },\n    'required': ['name', 'age']\n}\n\n# Compile the schema into a validator\nvalidator = load(schema)\n\n# Instance to validate\nvalid_instance = {'name': 'Alice', 'age': 30}\ninvalid_instance = {'name': 'Bob', 'age': -5}\nmissing_field_instance = {'name': 'Charlie'}\n\n# Perform validation\ntry:\n    validator.validate(valid_instance)\n    print(\"Valid instance is valid.\")\nexcept Exception as e:\n    print(f\"Valid instance failed validation: {e}\")\n\ntry:\n    validator.validate(invalid_instance)\n    print(\"Invalid instance (negative age) is valid.\")\nexcept Exception as e:\n    print(f\"Invalid instance (negative age) failed validation: {e}\")\n\ntry:\n    validator.validate(missing_field_instance)\n    print(\"Invalid instance (missing field) is valid.\")\nexcept Exception as e:\n    print(f\"Invalid instance (missing field) failed validation: {e}\")\n\n# Example of JSON Pointer (requires explicit import/use)\ndata_for_pointer = {'foo': ['bar', 'baz', {'qux': 10}]}\npointer = Pointer('/foo/2/qux')\nvalue = pointer.get(data_for_pointer)\nprint(f\"Value at /foo/2/qux: {value}\")","lang":"python","description":"This quickstart demonstrates how to define a JSON Schema, create a validator using `jsonspec.validators.load`, and validate JSON instances against it. It also includes a basic example of using JSON Pointer to extract a value from a JSON document. The `load` function defaults to JSON Schema Draft 04, but can be explicitly set to Draft 03 if needed."},"warnings":[{"fix":"For newer JSON Schema drafts, consider using the more actively maintained `jsonschema` library (pypi: `jsonschema`) which supports Draft 2020-12 and earlier modern drafts. If locked to older schemas, ensure your schemas conform to Draft 03 or Draft 04 specifications.","message":"The `json-spec` library primarily supports JSON Schema Draft 03 and Draft 04. This is a critical limitation as the JSON Schema specification has evolved significantly, with Draft 2020-12 being the latest standard. Users requiring features from newer drafts (e.g., Draft 07, 2019-09, 2020-12) will find this library insufficient or experience unexpected behavior.","severity":"breaking","affected_versions":"All versions of `json-spec` (including 0.12.0) that adhere to its stated Draft 03/04 support."},{"fix":"Ensure all JSON data (schemas and instances) strictly adhere to the JSON specification. Use linters, validators (like `json.tool` in Python's standard library), or IDE extensions to catch these errors early.","message":"Common JSON syntax errors (e.g., trailing commas, unquoted object keys, single quotes instead of double quotes for strings, comments within JSON) will result in parsing failures. While not specific to `json-spec`, these are frequent mistakes when authoring JSON schemas or instances.","severity":"gotcha","affected_versions":"All versions of `json-spec` (and generally any JSON parser)."},{"fix":"Be aware of potential ambiguities when designing complex schemas. Test your schemas with multiple JSON Schema validators if cross-platform or cross-implementation consistency is critical. Refer to the official JSON Schema specification for details on defined vs. undefined behaviors.","message":"The JSON Schema specification itself sometimes leaves certain behaviors 'undefined' leading to 'indeterminate' validation results. Different implementations of JSON Schema might resolve these ambiguities in varying ways, potentially leading to inconsistent validation outcomes across different tools or libraries.","severity":"gotcha","affected_versions":"All versions, as this is a characteristic of the JSON Schema specification itself."}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}