json-structure-summary 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Andrew Kingdom
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,230 @@
1
+ Metadata-Version: 2.4
2
+ Name: json-structure-summary
3
+ Version: 0.1.0
4
+ Summary: Infer and summarize the structure of any JSON file – even malformed ones – as a schema or human-readable tree.
5
+ Author: Andrew Kingdom
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/akingdom/json-structure-summary
8
+ Project-URL: Repository, https://github.com/akingdom/json-structure-summary
9
+ Project-URL: Issues, https://github.com/akingdom/json-structure-summary/issues
10
+ Keywords: json,schema,inference,validation,structural-analysis,cli,data-exploration
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.7
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Requires-Python: >=3.7
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE.md
24
+ Provides-Extra: test
25
+ Requires-Dist: pytest>=7.0; extra == "test"
26
+ Requires-Dist: pytest-cov>=4.0; extra == "test"
27
+ Dynamic: license-file
28
+
29
+ # JSON Structure Summary
30
+
31
+ **Infer and summarise the structure of any JSON file – even malformed ones – as a JSON Schema or a human‑readable tree.**
32
+
33
+ [![PyPI version](https://badge.fury.io/py/json-structure-summary.svg)](https://pypi.org/project/json-structure-summary/)
34
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
35
+
36
+ ---
37
+
38
+ ## Why do developers need this?
39
+
40
+ Working with unknown JSON data is a common pain point:
41
+
42
+ - You receive a large JSON file and have **no idea what’s inside**.
43
+ - The file is **malformed** (trailing commas, C‑style comments) and breaks normal parsers.
44
+ - You need to **generate a JSON Schema** for validation or documentation.
45
+ - You want to **quickly understand the structure** without reading thousands of lines.
46
+ - You need **statistics** (field presence, array lengths) to assess data quality.
47
+
48
+ **json-structure-summary** solves these problems in one command. It:
49
+
50
+ - **Repairs common JSON errors** (comments, trailing commas, BOM) automatically.
51
+ - **Infers a JSON Schema** (draft‑07) that accurately describes the data, including union types, optional fields, and nested structures.
52
+ - **Provides a human‑readable summary** with field presence and array length statistics.
53
+ - **Works as a library** so you can integrate it into your own Python tools.
54
+
55
+ 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.
56
+
57
+ ---
58
+
59
+ ## Features
60
+
61
+ - **Robust parsing** – strips `//` and `/* */` comments, removes trailing commas, handles byte‑order marks.
62
+ - **Schema inference** – outputs a standard JSON Schema (draft‑07) that you can use with validators like `jsonschema`.
63
+ - **Mixed‑type support** – arrays with different element types are represented using `anyOf`.
64
+ - **Optionality detection** – fields are marked `required` only if they appear in *every* object across the dataset.
65
+ - **Human‑readable summary** – prints a tree structure with type annotations and (optionally) statistics.
66
+ - **Statistics** – shows field presence counts and array length ranges (min, max, average).
67
+ - **Performance** – limit array sampling with `--max-samples` to handle huge files quickly.
68
+ - **Library friendly** – import `summarize_json_structure()` and use it programmatically.
69
+
70
+ ---
71
+
72
+ ## Installation
73
+
74
+ ```bash
75
+ pip install json-structure-summary
76
+ ```
77
+
78
+ Or install directly from source:
79
+
80
+ ```bash
81
+ git clone https://github.com/akingdom/json-structure-summary.git
82
+ cd json-structure-summary
83
+ pip install -e .
84
+ ```
85
+
86
+ ---
87
+
88
+ ## Usage
89
+
90
+ ### Command‑line interface
91
+
92
+ ```bash
93
+ # Basic usage – outputs JSON Schema
94
+ json-structure-summary data.json
95
+
96
+ # Human‑readable summary with statistics
97
+ json-structure-summary data.json --summary
98
+
99
+ # Pretty‑print the schema
100
+ json-structure-summary data.json --schema --pretty
101
+
102
+ # Limit array sampling to 100 elements for performance
103
+ json-structure-summary data.json --max-samples 100
104
+
105
+ # Read from stdin
106
+ cat data.json | json-structure-summary
107
+ ```
108
+
109
+ ### Options
110
+
111
+ | Option | Description |
112
+ |--------|-------------|
113
+ | `--schema` | Output a JSON Schema (default) |
114
+ | `--summary` | Output a human‑readable structural summary |
115
+ | `--pretty` | Pretty‑print the output (indent 2) |
116
+ | `--max-samples N` | Inspect at most N elements per array (default: all) |
117
+ | `--help` | Show help |
118
+
119
+ ---
120
+
121
+ ## Examples
122
+
123
+ ### Input JSON (with trailing commas and comments)
124
+
125
+ ```json
126
+ {
127
+ "users": [ // list of users
128
+ {"id": 1, "name": "Alice", "active": true,},
129
+ {"id": 2, "name": "Bob", "active": false, "tags": ["admin"]}
130
+ ]
131
+ }
132
+ ```
133
+
134
+ ### Output (schema, pretty‑printed)
135
+
136
+ ```json
137
+ {
138
+ "type": "object",
139
+ "properties": {
140
+ "users": {
141
+ "type": "array",
142
+ "items": {
143
+ "type": "object",
144
+ "properties": {
145
+ "id": { "type": "integer" },
146
+ "name": { "type": "string" },
147
+ "active": { "type": "boolean" },
148
+ "tags": {
149
+ "type": "array",
150
+ "items": { "type": "string" }
151
+ }
152
+ },
153
+ "required": ["id", "name", "active"] // 'tags' is optional
154
+ }
155
+ }
156
+ },
157
+ "required": ["users"]
158
+ }
159
+ ```
160
+
161
+ ### Summary output
162
+
163
+ ```
164
+ Object:
165
+ users:
166
+ Array of:
167
+ Object:
168
+ id:
169
+ integer
170
+ name:
171
+ string
172
+ active:
173
+ boolean
174
+ tags:
175
+ Array of:
176
+ string
177
+
178
+ Statistics:
179
+ $.users: lengths 2-2 (avg 2.0, 1 entries)
180
+ $.users[0].id: present in 1 objects
181
+ $.users[0].name: present in 1 objects
182
+ ...
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Using as a library
188
+
189
+ ```python
190
+ from json_structure_summary import summarize_json_structure
191
+
192
+ # From a file, get schema as string
193
+ schema_str = summarize_json_structure('data.json', pretty=True)
194
+
195
+ # From a file, get schema as dict
196
+ schema_dict = summarize_json_structure('data.json', return_type='dict')
197
+
198
+ # From a JSON string, get summary
199
+ summary = summarize_json_structure(
200
+ '{"x": 1, "y": "hello"}',
201
+ from_file=False,
202
+ output_format='summary'
203
+ )
204
+ print(summary)
205
+ ```
206
+
207
+ **Function signature:**
208
+
209
+ ```python
210
+ summarize_json_structure(
211
+ source: str,
212
+ from_file: bool = True,
213
+ output_format: Literal['schema', 'summary'] = 'schema',
214
+ pretty: bool = False,
215
+ max_samples: Optional[int] = None,
216
+ return_type: Literal['str', 'dict'] = 'str'
217
+ ) -> Union[str, Dict]
218
+ ```
219
+
220
+ ---
221
+
222
+ ## License
223
+
224
+ MIT License – see [LICENSE](LICENSE) for details.
225
+
226
+ ---
227
+
228
+ ## Contributing
229
+
230
+ Bug reports, feature requests, and pull requests are welcome on [GitHub](https://github.com/akingdom/json-structure-summary).
@@ -0,0 +1,202 @@
1
+ # JSON Structure Summary
2
+
3
+ **Infer and summarise the structure of any JSON file – even malformed ones – as a JSON Schema or a human‑readable tree.**
4
+
5
+ [![PyPI version](https://badge.fury.io/py/json-structure-summary.svg)](https://pypi.org/project/json-structure-summary/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ---
9
+
10
+ ## Why do developers need this?
11
+
12
+ Working with unknown JSON data is a common pain point:
13
+
14
+ - You receive a large JSON file and have **no idea what’s inside**.
15
+ - The file is **malformed** (trailing commas, C‑style comments) and breaks normal parsers.
16
+ - You need to **generate a JSON Schema** for validation or documentation.
17
+ - You want to **quickly understand the structure** without reading thousands of lines.
18
+ - You need **statistics** (field presence, array lengths) to assess data quality.
19
+
20
+ **json-structure-summary** solves these problems in one command. It:
21
+
22
+ - **Repairs common JSON errors** (comments, trailing commas, BOM) automatically.
23
+ - **Infers a JSON Schema** (draft‑07) that accurately describes the data, including union types, optional fields, and nested structures.
24
+ - **Provides a human‑readable summary** with field presence and array length statistics.
25
+ - **Works as a library** so you can integrate it into your own Python tools.
26
+
27
+ 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.
28
+
29
+ ---
30
+
31
+ ## Features
32
+
33
+ - **Robust parsing** – strips `//` and `/* */` comments, removes trailing commas, handles byte‑order marks.
34
+ - **Schema inference** – outputs a standard JSON Schema (draft‑07) that you can use with validators like `jsonschema`.
35
+ - **Mixed‑type support** – arrays with different element types are represented using `anyOf`.
36
+ - **Optionality detection** – fields are marked `required` only if they appear in *every* object across the dataset.
37
+ - **Human‑readable summary** – prints a tree structure with type annotations and (optionally) statistics.
38
+ - **Statistics** – shows field presence counts and array length ranges (min, max, average).
39
+ - **Performance** – limit array sampling with `--max-samples` to handle huge files quickly.
40
+ - **Library friendly** – import `summarize_json_structure()` and use it programmatically.
41
+
42
+ ---
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ pip install json-structure-summary
48
+ ```
49
+
50
+ Or install directly from source:
51
+
52
+ ```bash
53
+ git clone https://github.com/akingdom/json-structure-summary.git
54
+ cd json-structure-summary
55
+ pip install -e .
56
+ ```
57
+
58
+ ---
59
+
60
+ ## Usage
61
+
62
+ ### Command‑line interface
63
+
64
+ ```bash
65
+ # Basic usage – outputs JSON Schema
66
+ json-structure-summary data.json
67
+
68
+ # Human‑readable summary with statistics
69
+ json-structure-summary data.json --summary
70
+
71
+ # Pretty‑print the schema
72
+ json-structure-summary data.json --schema --pretty
73
+
74
+ # Limit array sampling to 100 elements for performance
75
+ json-structure-summary data.json --max-samples 100
76
+
77
+ # Read from stdin
78
+ cat data.json | json-structure-summary
79
+ ```
80
+
81
+ ### Options
82
+
83
+ | Option | Description |
84
+ |--------|-------------|
85
+ | `--schema` | Output a JSON Schema (default) |
86
+ | `--summary` | Output a human‑readable structural summary |
87
+ | `--pretty` | Pretty‑print the output (indent 2) |
88
+ | `--max-samples N` | Inspect at most N elements per array (default: all) |
89
+ | `--help` | Show help |
90
+
91
+ ---
92
+
93
+ ## Examples
94
+
95
+ ### Input JSON (with trailing commas and comments)
96
+
97
+ ```json
98
+ {
99
+ "users": [ // list of users
100
+ {"id": 1, "name": "Alice", "active": true,},
101
+ {"id": 2, "name": "Bob", "active": false, "tags": ["admin"]}
102
+ ]
103
+ }
104
+ ```
105
+
106
+ ### Output (schema, pretty‑printed)
107
+
108
+ ```json
109
+ {
110
+ "type": "object",
111
+ "properties": {
112
+ "users": {
113
+ "type": "array",
114
+ "items": {
115
+ "type": "object",
116
+ "properties": {
117
+ "id": { "type": "integer" },
118
+ "name": { "type": "string" },
119
+ "active": { "type": "boolean" },
120
+ "tags": {
121
+ "type": "array",
122
+ "items": { "type": "string" }
123
+ }
124
+ },
125
+ "required": ["id", "name", "active"] // 'tags' is optional
126
+ }
127
+ }
128
+ },
129
+ "required": ["users"]
130
+ }
131
+ ```
132
+
133
+ ### Summary output
134
+
135
+ ```
136
+ Object:
137
+ users:
138
+ Array of:
139
+ Object:
140
+ id:
141
+ integer
142
+ name:
143
+ string
144
+ active:
145
+ boolean
146
+ tags:
147
+ Array of:
148
+ string
149
+
150
+ Statistics:
151
+ $.users: lengths 2-2 (avg 2.0, 1 entries)
152
+ $.users[0].id: present in 1 objects
153
+ $.users[0].name: present in 1 objects
154
+ ...
155
+ ```
156
+
157
+ ---
158
+
159
+ ## Using as a library
160
+
161
+ ```python
162
+ from json_structure_summary import summarize_json_structure
163
+
164
+ # From a file, get schema as string
165
+ schema_str = summarize_json_structure('data.json', pretty=True)
166
+
167
+ # From a file, get schema as dict
168
+ schema_dict = summarize_json_structure('data.json', return_type='dict')
169
+
170
+ # From a JSON string, get summary
171
+ summary = summarize_json_structure(
172
+ '{"x": 1, "y": "hello"}',
173
+ from_file=False,
174
+ output_format='summary'
175
+ )
176
+ print(summary)
177
+ ```
178
+
179
+ **Function signature:**
180
+
181
+ ```python
182
+ summarize_json_structure(
183
+ source: str,
184
+ from_file: bool = True,
185
+ output_format: Literal['schema', 'summary'] = 'schema',
186
+ pretty: bool = False,
187
+ max_samples: Optional[int] = None,
188
+ return_type: Literal['str', 'dict'] = 'str'
189
+ ) -> Union[str, Dict]
190
+ ```
191
+
192
+ ---
193
+
194
+ ## License
195
+
196
+ MIT License – see [LICENSE](LICENSE) for details.
197
+
198
+ ---
199
+
200
+ ## Contributing
201
+
202
+ Bug reports, feature requests, and pull requests are welcome on [GitHub](https://github.com/akingdom/json-structure-summary).
@@ -0,0 +1,61 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "json-structure-summary"
7
+ dynamic = ["version"]
8
+ description = "Infer and summarize the structure of any JSON file – even malformed ones – as a schema or human-readable tree."
9
+ readme = "README.md"
10
+ requires-python = ">=3.7"
11
+ license = "MIT"
12
+ authors = [
13
+ { name = "Andrew Kingdom" }
14
+ ]
15
+ keywords = [
16
+ "json",
17
+ "schema",
18
+ "inference",
19
+ "validation",
20
+ "structural-analysis",
21
+ "cli",
22
+ "data-exploration"
23
+ ]
24
+ classifiers = [
25
+ "Development Status :: 4 - Beta",
26
+ "Intended Audience :: Developers",
27
+ "Topic :: Software Development :: Libraries :: Python Modules",
28
+ "Programming Language :: Python :: 3",
29
+ "Programming Language :: Python :: 3.7",
30
+ "Programming Language :: Python :: 3.8",
31
+ "Programming Language :: Python :: 3.9",
32
+ "Programming Language :: Python :: 3.10",
33
+ "Programming Language :: Python :: 3.11",
34
+ "Programming Language :: Python :: 3.12",
35
+ ]
36
+ dependencies = [] # only uses the standard library
37
+
38
+ [project.optional-dependencies]
39
+ test = ["pytest>=7.0", "pytest-cov>=4.0"]
40
+
41
+ [project.urls]
42
+ Homepage = "https://github.com/akingdom/json-structure-summary"
43
+ Repository = "https://github.com/akingdom/json-structure-summary"
44
+ Issues = "https://github.com/akingdom/json-structure-summary/issues"
45
+
46
+ [project.scripts]
47
+ json-structure-summary = "json_structure_summary:main"
48
+
49
+ [tool.setuptools.dynamic]
50
+ version = { attr = "json_structure_summary.__version__" }
51
+
52
+ [tool.setuptools.packages.find]
53
+ where = ["src"]
54
+ # This will automatically find any package under src/ that is a valid Python package name.
55
+ # Our package is now "json_structure_summary" (with underscores) – it will be discovered.
56
+
57
+ [tool.pytest.ini_options]
58
+ minversion = "7.0"
59
+ addopts = "-ra -q --cov=json_structure_summary --cov-report=term-missing"
60
+ testpaths = ["tests"] # change to "test" if you keep that folder
61
+ python_files = "test_*.py"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,10 @@
1
+ """json_structure_summary: Infer and summarize the structure of any JSON file, even malformed ones."""
2
+
3
+ from .core import summarize_json_structure, main
4
+
5
+ __version__ = "0.1.0"
6
+ __all__ = [
7
+ "__version__",
8
+ "summarize_json_structure",
9
+ "main",
10
+ ]