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.0

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.0
File Size Uploaded
jsonbp-1.3.0.tar.gz 57.1 kB Details

Built distribution (wheel)

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

Total release size: 116.2 kB

Release files / jsonbp-1.3.0.tar.gz

Download URL jsonbp-1.3.0.tar.gz
Size 57.1 kB
Tags Source
SHA-256 checksum
How to use checksums
dafc78cd6214985dcb768339627d78062d3f202e04a02ac678fa0197b6768f73
BLAKE2b-256 checksum
How to use checksums
8990da021674ee6294d632e85104531d2b0eb1bf2f954466c969d20d85898eba
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.0-py3-none-any.whl

Download URL jsonbp-1.3.0-py3-none-any.whl
Size 59.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6d233b6d06d17b967aad1a9f536bea50fd6528962aa92d57fffe1230d29d8298
BLAKE2b-256 checksum
How to use checksums
7c2b5f4a2f03e7c96b3d5d70459176fb423f804f7ae2ed53223c0297718d1c1f
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

1.3.1

2 release files

This release

1.3.0 This release

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