JSON Structure Summary
Infer and summarise the structure of any JSON file – even malformed ones – as a JSON Schema or a human‑readable tree.
Why do developers need this?
Working with unknown JSON data is a common pain point:
- You receive a large JSON file and have no idea what’s inside.
- The file is malformed (trailing commas, C‑style comments) and breaks normal parsers.
- You need to generate a JSON Schema for validation or documentation.
- You want to quickly understand the structure without reading thousands of lines.
- You need statistics (field presence, array lengths) to assess data quality.
json-structure-summary solves these problems in one command. It:
- Repairs common JSON errors (comments, trailing commas, BOM) automatically.
- Infers a JSON Schema (draft‑07) that accurately describes the data, including union types, optional fields, and nested structures.
- Provides a human‑readable summary with field presence and array length statistics.
- Works as a library so you can integrate it into your own Python tools.
Whether you’re exploring a new API response, debugging a data pipeline, or writing documentation, this tool gives you instant insight into your JSON data.
Features
- Robust parsing – strips
//and/* */comments, removes trailing commas, handles byte‑order marks. - Schema inference – outputs a standard JSON Schema (draft‑07) that you can use with validators like
jsonschema. - Mixed‑type support – arrays with different element types are represented using
anyOf. - Optionality detection – fields are marked
requiredonly if they appear in every object across the dataset. - Human‑readable summary – prints a tree structure with type annotations and (optionally) statistics.
- Statistics – shows field presence counts and array length ranges (min, max, average).
- Performance – limit array sampling with
--max-samplesto handle huge files quickly. - Library friendly – import
summarize_json_structure()and use it programmatically.
Installation
pip install json-structure-summary
Or install directly from source:
git clone https://github.com/akingdom/json-structure-summary.git
cd json-structure-summary
pip install -e .
Usage
Command‑line interface
# Basic usage – outputs JSON Schema
json-structure-summary data.json
# Human‑readable summary with statistics
json-structure-summary data.json --summary
# Pretty‑print the schema
json-structure-summary data.json --schema --pretty
# Limit array sampling to 100 elements for performance
json-structure-summary data.json --max-samples 100
# Read from stdin
cat data.json | json-structure-summary
Options
| Option | Description |
|---|---|
--schema |
Output a JSON Schema (default) |
--summary |
Output a human‑readable structural summary |
--pretty |
Pretty‑print the output (indent 2) |
--max-samples N |
Inspect at most N elements per array (default: all) |
--help |
Show help |
Examples
Input JSON (with trailing commas and comments)
{
"users": [ // list of users
{"id": 1, "name": "Alice", "active": true,},
{"id": 2, "name": "Bob", "active": false, "tags": ["admin"]}
]
}
Output (schema, pretty‑printed)
{
"type": "object",
"properties": {
"users": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"active": { "type": "boolean" },
"tags": {
"type": "array",
"items": { "type": "string" }
}
},
"required": ["id", "name", "active"] // 'tags' is optional
}
}
},
"required": ["users"]
}
Summary output
Object:
users:
Array of:
Object:
id:
integer
name:
string
active:
boolean
tags:
Array of:
string
Statistics:
$.users: lengths 2-2 (avg 2.0, 1 entries)
$.users[0].id: present in 1 objects
$.users[0].name: present in 1 objects
...
Using as a library
from json_structure_summary import summarize_json_structure
# From a file, get schema as string
schema_str = summarize_json_structure('data.json', pretty=True)
# From a file, get schema as dict
schema_dict = summarize_json_structure('data.json', return_type='dict')
# From a JSON string, get summary
summary = summarize_json_structure(
'{"x": 1, "y": "hello"}',
from_file=False,
output_format='summary'
)
print(summary)
Function signature:
summarize_json_structure(
source: str,
from_file: bool = True,
output_format: Literal['schema', 'summary'] = 'schema',
pretty: bool = False,
max_samples: Optional[int] = None,
return_type: Literal['str', 'dict'] = 'str'
) -> Union[str, Dict]
License
MIT License – see LICENSE for details.
Contributing
Bug reports, feature requests, and pull requests are welcome on GitHub.
Metadata
Release files for json-structure-summary 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| json_structure_summary-0.1.0.tar.gz | 13.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| json_structure_summary-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.5 kB
Release files / json_structure_summary-0.1.0.tar.gz
| Download URL | json_structure_summary-0.1.0.tar.gz |
|---|---|
| Size | 13.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17e4a8ad5dc631f2f4b256b0d1d75f303f4c2f364ed0e706569095b4b917864d
|
|
BLAKE2b-256 checksum How to use checksums |
9aa15d4636aab50158ee105165a5d59d3dce757ae7dd419ba39b6eba2bf26912
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.13
|
Release files / json_structure_summary-0.1.0-py3-none-any.whl
| Download URL | json_structure_summary-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
761a7b0e8ae79b7869ba360fa94ea14f1a0f14446aec8afcd47d7f71a0509847
|
|
BLAKE2b-256 checksum How to use checksums |
091355d00874dc33f2ad5305ab6fc0e34bf85e9743440e6ea5085433e93aa6b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.13
|
Security for json-structure-summary 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.