Skip to main content

jsonbp

Documentation Status codecov

jsonbp (JSON BluePrint) is a library for serializing and deserializing JSON to and from Python based on schemas. While json-schema and its implementations offer a more mature and widely used technique, a different approach was desired, which led to the development of this library.

jsonbp's main design goals were:

  • schema reuse through import / type system
  • custom user definable primitive types
  • built in numeric fixed precision type which deserializes into Python's Decimal
  • built in datetime type which deserializes into Python's datetime
  • error reporting with support for localization
  • support for enums
  • easy to integrate and use

Brief Introduction

Schema definition

jsonbp uses its own (very simple) domain language to define a schema. Here's a simple example:

root {
  x: Float (min=0.0),
  y: Float (min=0.0, max=1.0),

  optional Color: {
    RED,
    GOLD,
    GREEN
  }
} [minLength=2]

This defines a schema that represents an array of minimum length 2 whose elements contain the fields 'x' and 'y', where both 'x' and 'y' are not allowed to be negative and further 'y' is not allowed to be greater than 1.0. An optional field 'color' can also exist, and if present it needs to be either "RED", "GOLD" or "GREEN". A JSON instance that obeys this schema is thus:

[
  {
    "x": 2.0,
    "y", 0.004,
    "color": "RED"
  },

  {
    "x": 3.0,
    "y", 0.009
  },

  {
    "x": 4.0,
    "y", 0.016,
    "color": "GREEN"
  }
]

jsonbp offers the following directives to organize a schema:

  • "root" -> defines which type will correspond to some JSON
  • "type" -> defines specialized (restricted) simple types
  • "object" -> specifies the contents of compound types (Objects)
  • "enum" -> defines a list of allowed values for a given field
  • "import" -> reuses directives from existing blueprints

These structures can be employed to simplify and make the schema more modular. In the above example, one could split the definitions and get something more reusable, like the following:

type NonNegative : Float (min=0.0)
type Normalized : NonNegative (max=1.0)

object Coordinates {
  x: NonNegative,
  y: Normalized
}

include "color.jbp"
object ColoredCoordinates extends Coordinates {
  optional color: Color
}

root ColoredCoordinates[minLength=2]

where the contents of file "color.jbp" would be:

enum Color {
  RED,
  GOLD,
  GREEN
}

NOTE: For full documentation, see Documentation

Usage overview

Schema parsing

  • jsonbp.load_file(blueprint_path: str) => JsonBlueprint
  • jsonbp.load_string(blueprint_string: str) => JsonBlueprint

JSON deserialization

  • JsonBlueprint.deserialize(contents: str) => (success: bool, outcome: object)
  • JsonBlueprint.serialize(payload: object) => str

Example

import jsonbp

blueprint = jsonbp.load_string('''
root {
  success: {
    YES,
    NO
  }
}
''')

jsonInstance = '{ "success": "YES" }'
success, outcome = blueprint.deserialize(jsonInstance)
print(f'Success: {success}')
print(f'Outcome: {outcome}')

Output:

Success: true
Outcome: {"success":"YES"}

NOTE: For full documentation, see Documentation

Requirements and Dependencies

jsonbp requires Python 3.11+, that's it. Under the hood, jsonbp uses PLY for its schema parsing. PLY comes included with jsonbp already, there's no need to download it separately.

Installation

jsonbp is available at PyPI: https://pypi.org/project/jsonbp/

To install through pip:

pip install jsonbp

Documentation

Metadata

Release files for jsonbp 1.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonbp 1.3.1
File Size Uploaded
jsonbp-1.3.1.tar.gz 59.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jsonbp 1.3.1
File Interpreter ABI Platform
jsonbp-1.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 122.2 kB

Release files / jsonbp-1.3.1.tar.gz

Download URL jsonbp-1.3.1.tar.gz
Size 59.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2efb8ccf0d1ed0b7304b220055f8617a2160bbec3a9665e8e6d07804450acd25
BLAKE2b-256 checksum
How to use checksums
77f0770e758bc98d7b3c3c8456f6f53d7d057d79d2ca9f231d07d394fdb4e5a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / jsonbp-1.3.1-py3-none-any.whl

Download URL jsonbp-1.3.1-py3-none-any.whl
Size 63.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
703098f7d439548166c6018ae4c70ab7bf9546d23daafc2b00e2cf466ca01371
BLAKE2b-256 checksum
How to use checksums
86d6d665821630e35819e9587a6c7cda39acacb6965fcb83191fa216d7f7fb19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.3.1 This release

2 release files

1.3.0

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.2

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.2

2 release files

0.9.1

1 release file

0.9.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page