py-json-analyzer 0.2.0__tar.gz → 0.4.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.
- py_json_analyzer-0.4.0/PKG-INFO +790 -0
- py_json_analyzer-0.4.0/README.md +741 -0
- py_json_analyzer-0.4.0/json_explorer/__init__.py +30 -0
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/json_explorer/analyzer.py +98 -72
- py_json_analyzer-0.4.0/json_explorer/cli.py +161 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/__init__.py +224 -0
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/json_explorer/codegen/cli_integration.py +278 -141
- py_json_analyzer-0.4.0/json_explorer/codegen/core/__init__.py +98 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/core/config.py +346 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/core/generator.py +379 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/core/naming.py +338 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/core/schema.py +583 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/core/templates.py +285 -0
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/json_explorer/codegen/interactive.py +255 -169
- py_json_analyzer-0.4.0/json_explorer/codegen/languages/__init__.py +189 -0
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/json_explorer/codegen/languages/go/__init__.py +10 -15
- py_json_analyzer-0.4.0/json_explorer/codegen/languages/go/config.py +226 -0
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/json_explorer/codegen/languages/go/generator.py +138 -89
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/json_explorer/codegen/languages/go/interactive.py +134 -123
- py_json_analyzer-0.4.0/json_explorer/codegen/languages/go/naming.py +104 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/languages/go/templates/complete_file.go.j2 +29 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/languages/go/templates/json_tag.go.j2 +1 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/languages/python/__init__.py +43 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/languages/python/config.py +329 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/languages/python/generator.py +423 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/languages/python/interactive.py +352 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/languages/python/naming.py +158 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/languages/python/templates/dataclass_file.py.j2 +34 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/languages/python/templates/pydantic_file.py.j2 +38 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/languages/python/templates/typeddict_file.py.j2 +26 -0
- py_json_analyzer-0.4.0/json_explorer/codegen/registry.py +396 -0
- py_json_analyzer-0.4.0/json_explorer/interactive.py +344 -0
- py_json_analyzer-0.4.0/json_explorer/logging_config.py +72 -0
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/json_explorer/main.py +115 -64
- py_json_analyzer-0.4.0/json_explorer/search.py +307 -0
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/json_explorer/stats.py +129 -72
- py_json_analyzer-0.4.0/json_explorer/tree_view.py +224 -0
- py_json_analyzer-0.4.0/json_explorer/utils.py +237 -0
- py_json_analyzer-0.4.0/json_explorer/visualizer.py +679 -0
- py_json_analyzer-0.4.0/py_json_analyzer.egg-info/PKG-INFO +790 -0
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/py_json_analyzer.egg-info/SOURCES.txt +23 -4
- py_json_analyzer-0.4.0/py_json_analyzer.egg-info/requires.txt +23 -0
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/py_json_analyzer.egg-info/top_level.txt +0 -1
- py_json_analyzer-0.4.0/pyproject.toml +201 -0
- py_json_analyzer-0.4.0/setup.cfg +4 -0
- py_json_analyzer-0.4.0/tests/test_gen_conftest.py +44 -0
- py_json_analyzer-0.4.0/tests/test_gen_core_config.py +92 -0
- py_json_analyzer-0.4.0/tests/test_gen_core_naming.py +81 -0
- py_json_analyzer-0.4.0/tests/test_gen_core_schema.py +161 -0
- py_json_analyzer-0.4.0/tests/test_gen_edge.py +512 -0
- py_json_analyzer-0.4.0/tests/test_gen_error_handling.py +27 -0
- py_json_analyzer-0.4.0/tests/test_gen_integration.py +185 -0
- py_json_analyzer-0.4.0/tests/test_gen_performance.py +37 -0
- py_json_analyzer-0.4.0/tests/test_gen_registry.py +110 -0
- py_json_analyzer-0.4.0/tests/test_gen_templates.py +32 -0
- py_json_analyzer-0.4.0/tests/test_go_generator.py +187 -0
- py_json_analyzer-0.4.0/tests/test_python_generator.py +230 -0
- py_json_analyzer-0.4.0/tests/test_search.py +293 -0
- py_json_analyzer-0.4.0/tests/test_tree_view.py +579 -0
- py_json_analyzer-0.4.0/tests/test_utils.py +537 -0
- py_json_analyzer-0.4.0/tests/test_visualizer.py +432 -0
- py_json_analyzer-0.2.0/PKG-INFO +0 -416
- py_json_analyzer-0.2.0/README.md +0 -397
- py_json_analyzer-0.2.0/json_explorer/__init__.py +0 -1
- py_json_analyzer-0.2.0/json_explorer/cli.py +0 -139
- py_json_analyzer-0.2.0/json_explorer/codegen/__init__.py +0 -178
- py_json_analyzer-0.2.0/json_explorer/codegen/core/__init__.py +0 -41
- py_json_analyzer-0.2.0/json_explorer/codegen/core/config.py +0 -170
- py_json_analyzer-0.2.0/json_explorer/codegen/core/generator.py +0 -212
- py_json_analyzer-0.2.0/json_explorer/codegen/core/naming.py +0 -175
- py_json_analyzer-0.2.0/json_explorer/codegen/core/schema.py +0 -483
- py_json_analyzer-0.2.0/json_explorer/codegen/core/templates.py +0 -174
- py_json_analyzer-0.2.0/json_explorer/codegen/languages/__init__.py +0 -35
- py_json_analyzer-0.2.0/json_explorer/codegen/languages/go/config.py +0 -115
- py_json_analyzer-0.2.0/json_explorer/codegen/languages/go/naming.py +0 -81
- py_json_analyzer-0.2.0/json_explorer/codegen/registry.py +0 -355
- py_json_analyzer-0.2.0/json_explorer/filter_parser.py +0 -132
- py_json_analyzer-0.2.0/json_explorer/interactive.py +0 -504
- py_json_analyzer-0.2.0/json_explorer/search.py +0 -423
- py_json_analyzer-0.2.0/json_explorer/tree_view.py +0 -161
- py_json_analyzer-0.2.0/json_explorer/utils.py +0 -114
- py_json_analyzer-0.2.0/json_explorer/visualizer.py +0 -1060
- py_json_analyzer-0.2.0/py_json_analyzer.egg-info/PKG-INFO +0 -416
- py_json_analyzer-0.2.0/py_json_analyzer.egg-info/requires.txt +0 -9
- py_json_analyzer-0.2.0/pyproject.toml +0 -26
- py_json_analyzer-0.2.0/setup.cfg +0 -29
- py_json_analyzer-0.2.0/setup.py +0 -3
- py_json_analyzer-0.2.0/tests/__init__.py +0 -0
- py_json_analyzer-0.2.0/tests/test_search.py +0 -192
- py_json_analyzer-0.2.0/tests/test_tree_view.py +0 -188
- py_json_analyzer-0.2.0/tests/test_utils.py +0 -109
- py_json_analyzer-0.2.0/tests/test_visualizer.py +0 -96
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/LICENSE +0 -0
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/json_explorer/__main__.py +0 -0
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/py_json_analyzer.egg-info/dependency_links.txt +0 -0
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/py_json_analyzer.egg-info/entry_points.txt +0 -0
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/tests/test_analyzer.py +0 -0
- {py_json_analyzer-0.2.0 → py_json_analyzer-0.4.0}/tests/test_stats.py +0 -0
|
@@ -0,0 +1,790 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py-json-analyzer
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: A powerful CLI and Python library for analyzing, visualizing, exploring, and generating code from JSON data
|
|
5
|
+
Author-email: MS-32154 <msttoffg@gmail.com>
|
|
6
|
+
Maintainer-email: MS-32154 <msttoffg@gmail.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/MS-32154/py-json-analyzer
|
|
9
|
+
Project-URL: Documentation, https://ms-32154.github.io/py-json-analyzer/
|
|
10
|
+
Project-URL: Repository, https://github.com/MS-32154/py-json-analyzer
|
|
11
|
+
Project-URL: Bug Tracker, https://github.com/MS-32154/py-json-analyzer/issues
|
|
12
|
+
Project-URL: Changelog, https://github.com/MS-32154/py-json-analyzer/blob/main/CHANGELOG.md
|
|
13
|
+
Keywords: json,analyzer,visualization,json-statistics,plot,jmespath,json-search,cli,interactive-cli,data-analysis,schema,code-generation,go,json-to-go,json-to-golang,python,pydantic,dataclass,json-to-python
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Topic :: Utilities
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.11
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: jmespath>=1.0.1
|
|
30
|
+
Requires-Dist: rich>=13.0.0
|
|
31
|
+
Requires-Dist: plotly>=5.0.0
|
|
32
|
+
Requires-Dist: requests>=2.32.0
|
|
33
|
+
Requires-Dist: dateparser>=1.2.0
|
|
34
|
+
Requires-Dist: jinja2>=3.0.0
|
|
35
|
+
Requires-Dist: prompt-toolkit>=3.0.0
|
|
36
|
+
Requires-Dist: windows-curses; sys_platform == "win32"
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
40
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
41
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
42
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
43
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
44
|
+
Requires-Dist: types-requests>=2.31.0; extra == "dev"
|
|
45
|
+
Requires-Dist: types-dateparser>=1.1.0; extra == "dev"
|
|
46
|
+
Provides-Extra: all
|
|
47
|
+
Requires-Dist: py-json-analyzer[dev]; extra == "all"
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
|
|
50
|
+
[](https://pypi.org/project/py-json-analyzer/)
|
|
51
|
+
[](https://www.python.org/downloads/)
|
|
52
|
+
[](https://opensource.org/licenses/MIT)
|
|
53
|
+
|
|
54
|
+
# JSON Explorer
|
|
55
|
+
|
|
56
|
+
**JSON Explorer** is a powerful CLI and Python library for analyzing, visualizing, exploring, and generating code from JSON data. Built with modern Python practices and featuring JMESPath-powered search capabilities.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Features
|
|
61
|
+
|
|
62
|
+
### Analysis & Exploration
|
|
63
|
+
|
|
64
|
+
- **Structural Analysis**: Deep JSON structure analysis with type detection and conflict resolution
|
|
65
|
+
- **JMESPath Search**: Industry-standard query language for powerful JSON searching and filtering
|
|
66
|
+
- **Tree Visualization**: Multiple view modes (compact, analytical, raw) with rich terminal output
|
|
67
|
+
- **Statistical Analysis**: Comprehensive data quality metrics and structural insights
|
|
68
|
+
- **Multi-Format Visualization**: Terminal (curses/ASCII), interactive HTML (Plotly), or combined output
|
|
69
|
+
- **Interactive Mode**: Full-featured terminal UI for exploration and analysis
|
|
70
|
+
|
|
71
|
+
### Code Generation
|
|
72
|
+
|
|
73
|
+
- **Multi-Language Support**: Generate strongly-typed code from JSON schemas
|
|
74
|
+
- **Go**: Structs with JSON tags, pointer handling, configurable types
|
|
75
|
+
- **Python**: Dataclasses, Pydantic v2 models, TypedDict with type hints
|
|
76
|
+
- **Coming Soon**: TypeScript interfaces, Rust structs with Serde
|
|
77
|
+
- **Smart Type Detection**: Automatic conflict resolution and optional field handling
|
|
78
|
+
- **Flexible Configuration**: Template-based system with extensive customization
|
|
79
|
+
- **Interactive Configuration**: Guided setup with real-time preview and validation
|
|
80
|
+
|
|
81
|
+
### Library Features
|
|
82
|
+
|
|
83
|
+
- **Modular Architecture**: Use individual components independently
|
|
84
|
+
- **Extensible Design**: Plugin-based generator system for custom languages
|
|
85
|
+
- **Production Ready**: Comprehensive error handling and logging
|
|
86
|
+
- **Well Documented**: Extensive API documentation and examples
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Requirements
|
|
91
|
+
|
|
92
|
+
- **Python**: 3.11 or higher
|
|
93
|
+
|
|
94
|
+
### Core Dependencies
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
dateparser>=1.2.0 # Timestamp detection
|
|
98
|
+
jmespath>=1.0.1 # JMESPath query language
|
|
99
|
+
jinja2>=3.0.0 # Template engine for code generation
|
|
100
|
+
plotly>=5.0.0 # Interactive, browser-based graphing
|
|
101
|
+
prompt-toolkit>=3.0.0 # Interactive input with autocomplete
|
|
102
|
+
requests>=2.32.0 # HTTP requests for URL loading
|
|
103
|
+
rich>=13.0.0 # Rich terminal formatting
|
|
104
|
+
windows-curses>=2.4.0 # Terminal UI support on Windows (auto-installed)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Optional Dependencies
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
pytest>=7.0.0
|
|
111
|
+
pytest-cov>=4.0.0
|
|
112
|
+
black>=23.0.0
|
|
113
|
+
isort>=5.12.0
|
|
114
|
+
mypy>=1.0.0
|
|
115
|
+
flake8>=6.0.0
|
|
116
|
+
types-requests>=2.31.0
|
|
117
|
+
types-dateparser>=1.1.0
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Installation
|
|
123
|
+
|
|
124
|
+
### From PyPI (Recommended)
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
pip install py-json-analyzer
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Upgrade to the latest version:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
pip install --upgrade py-json-analyzer
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### From Source
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
git clone https://github.com/MS-32154/py-json-analyzer
|
|
140
|
+
cd py-json-analyzer
|
|
141
|
+
pip install -e .
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
For development with all optional dependencies:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
pip install -e ".[dev]"
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Quick Start
|
|
153
|
+
|
|
154
|
+
### Command Line
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
# Interactive mode (recommended for first-time users)
|
|
158
|
+
json_explorer data.json --interactive
|
|
159
|
+
|
|
160
|
+
# Quick analysis
|
|
161
|
+
json_explorer data.json --tree compact --stats
|
|
162
|
+
|
|
163
|
+
# JMESPath search
|
|
164
|
+
json_explorer data.json --search "users[*].email"
|
|
165
|
+
|
|
166
|
+
# Generate Go code
|
|
167
|
+
json_explorer data.json --generate go --output models.go
|
|
168
|
+
|
|
169
|
+
# Generate Pydantic models
|
|
170
|
+
json_explorer data.json --generate python --python-style pydantic --output models.py
|
|
171
|
+
|
|
172
|
+
# Create visualizations
|
|
173
|
+
json_explorer data.json --plot --plot-format html
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Python Library
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
from json_explorer import analyze_json, JsonSearcher, quick_generate
|
|
180
|
+
|
|
181
|
+
# Analyze structure
|
|
182
|
+
data = {"users": [{"id": 1, "name": "Alice", "email": "alice@example.com"}]}
|
|
183
|
+
analysis = analyze_json(data)
|
|
184
|
+
print(analysis)
|
|
185
|
+
|
|
186
|
+
# JMESPath search
|
|
187
|
+
searcher = JsonSearcher()
|
|
188
|
+
result = searcher.search(data, "users[*].email")
|
|
189
|
+
searcher.print_result(result)
|
|
190
|
+
|
|
191
|
+
# Generate code
|
|
192
|
+
go_code = quick_generate(data, language="go", package_name="models")
|
|
193
|
+
python_code = quick_generate(data, language="python", style="pydantic")
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## CLI Usage
|
|
199
|
+
|
|
200
|
+
### Basic Commands
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
json_explorer [FILE] [OPTIONS]
|
|
204
|
+
|
|
205
|
+
# Data Sources
|
|
206
|
+
json_explorer data.json # Load from file
|
|
207
|
+
json_explorer --url https://api.example.com/data # Load from URL
|
|
208
|
+
|
|
209
|
+
# Display Modes
|
|
210
|
+
--interactive, -i # Interactive mode (full UI)
|
|
211
|
+
--tree {compact,analysis,raw} # Display tree structure
|
|
212
|
+
--stats # Show statistics
|
|
213
|
+
--detailed # Show detailed information
|
|
214
|
+
--plot # Generate visualizations
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### JMESPath Search
|
|
218
|
+
|
|
219
|
+
The search functionality now uses [JMESPath](https://jmespath.org/), an industry-standard query language for JSON:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
# Basic path expressions
|
|
223
|
+
json_explorer data.json --search "users" # Get users array
|
|
224
|
+
json_explorer data.json --search "users[0]" # First user
|
|
225
|
+
json_explorer data.json --search "users[*].name" # All names
|
|
226
|
+
|
|
227
|
+
# Filtering
|
|
228
|
+
json_explorer data.json --search "users[?age > \`30\`]" # Filter by age
|
|
229
|
+
json_explorer data.json --search "users[?active == \`true\`]" # Filter by boolean
|
|
230
|
+
|
|
231
|
+
# Functions
|
|
232
|
+
json_explorer data.json --search "length(users)" # Count users
|
|
233
|
+
json_explorer data.json --search "sort_by(users, &age)" # Sort by field
|
|
234
|
+
json_explorer data.json --search "max_by(users, &age).name" # Get name of oldest
|
|
235
|
+
|
|
236
|
+
# Projections (field selection)
|
|
237
|
+
json_explorer data.json --search "users[*].{name: name, email: email}"
|
|
238
|
+
|
|
239
|
+
# Complex queries
|
|
240
|
+
json_explorer data.json --search "users[?age > \`30\` && active == \`true\`].name"
|
|
241
|
+
|
|
242
|
+
# Display options
|
|
243
|
+
--tree-results # Show results as tree
|
|
244
|
+
--show-examples # Display JMESPath examples
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
**JMESPath Resources:**
|
|
248
|
+
|
|
249
|
+
- [Tutorial](https://jmespath.org/tutorial.html)
|
|
250
|
+
- [Specification](https://jmespath.org/specification.html)
|
|
251
|
+
- [Online Playground](https://jmespath.org/)
|
|
252
|
+
|
|
253
|
+
### Code Generation
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
# List supported languages
|
|
257
|
+
json_explorer --list-languages
|
|
258
|
+
|
|
259
|
+
# Get language details
|
|
260
|
+
json_explorer --language-info go
|
|
261
|
+
json_explorer --language-info python
|
|
262
|
+
|
|
263
|
+
# Generate Go code
|
|
264
|
+
json_explorer data.json --generate go \
|
|
265
|
+
--output models.go \
|
|
266
|
+
--package-name models \
|
|
267
|
+
--root-name User
|
|
268
|
+
|
|
269
|
+
# Go-specific options
|
|
270
|
+
--no-pointers # Don't use pointers for optional fields
|
|
271
|
+
--no-json-tags # Don't generate JSON tags
|
|
272
|
+
--json-tag-case {original,snake,camel}
|
|
273
|
+
|
|
274
|
+
# Generate Python code
|
|
275
|
+
json_explorer data.json --generate python \
|
|
276
|
+
--output models.py \
|
|
277
|
+
--python-style {dataclass,pydantic,typeddict}
|
|
278
|
+
|
|
279
|
+
# Python-specific options
|
|
280
|
+
--frozen # Make dataclasses immutable
|
|
281
|
+
--no-slots # Don't use __slots__
|
|
282
|
+
--kw-only # Make fields keyword-only
|
|
283
|
+
--pydantic-forbid-extra # Forbid extra fields in Pydantic
|
|
284
|
+
|
|
285
|
+
# Common options
|
|
286
|
+
--config config.json # Load configuration from file
|
|
287
|
+
--struct-case {pascal,camel,snake} # Class/struct name convention
|
|
288
|
+
--field-case {pascal,camel,snake} # Field name convention
|
|
289
|
+
--no-comments # Don't generate comments
|
|
290
|
+
--verbose # Show detailed generation info
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Visualization
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
# Terminal visualization (ASCII/curses)
|
|
297
|
+
json_explorer data.json --plot --plot-format terminal
|
|
298
|
+
|
|
299
|
+
# Interactive HTML (Plotly)
|
|
300
|
+
json_explorer data.json --plot --plot-format html
|
|
301
|
+
|
|
302
|
+
# All formats
|
|
303
|
+
json_explorer data.json --plot --plot-format all
|
|
304
|
+
|
|
305
|
+
# Options
|
|
306
|
+
--detailed # Generate detailed charts
|
|
307
|
+
--save-path output.html # Save to specific file
|
|
308
|
+
--no-browser # Don't auto-open browser
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Logging
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
--log-level {DEBUG,INFO,WARNING,ERROR}
|
|
315
|
+
--log-file output.log
|
|
316
|
+
--verbose-logging, -vl
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## Python API
|
|
322
|
+
|
|
323
|
+
### Core Analysis
|
|
324
|
+
|
|
325
|
+
```python
|
|
326
|
+
from json_explorer import analyze_json, load_json
|
|
327
|
+
|
|
328
|
+
# Load data
|
|
329
|
+
source, data = load_json("data.json")
|
|
330
|
+
# or
|
|
331
|
+
source, data = load_json(url="https://api.example.com/data")
|
|
332
|
+
|
|
333
|
+
# Analyze structure
|
|
334
|
+
analysis = analyze_json(data)
|
|
335
|
+
print(f"Type: {analysis['type']}")
|
|
336
|
+
print(f"Children: {analysis.get('children', {})}")
|
|
337
|
+
print(f"Conflicts: {analysis.get('conflicts', {})}")
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### JMESPath Search
|
|
341
|
+
|
|
342
|
+
```python
|
|
343
|
+
from json_explorer import JsonSearcher
|
|
344
|
+
|
|
345
|
+
searcher = JsonSearcher()
|
|
346
|
+
|
|
347
|
+
# Basic search
|
|
348
|
+
result = searcher.search(data, "users[*].email")
|
|
349
|
+
if result:
|
|
350
|
+
searcher.print_result(result)
|
|
351
|
+
|
|
352
|
+
# Multiple queries
|
|
353
|
+
queries = [
|
|
354
|
+
"users[*].name",
|
|
355
|
+
"users[?age > `30`]",
|
|
356
|
+
"length(users)"
|
|
357
|
+
]
|
|
358
|
+
results = searcher.search_multiple(data, queries)
|
|
359
|
+
|
|
360
|
+
# Validate query before executing
|
|
361
|
+
valid, error = searcher.validate_query("users[*].invalid...")
|
|
362
|
+
if valid:
|
|
363
|
+
result = searcher.search(data, query)
|
|
364
|
+
|
|
365
|
+
# Get example queries
|
|
366
|
+
examples = searcher.get_query_examples()
|
|
367
|
+
searcher.print_examples()
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Statistics & Analysis
|
|
371
|
+
|
|
372
|
+
```python
|
|
373
|
+
from json_explorer import DataStatsAnalyzer, generate_stats
|
|
374
|
+
|
|
375
|
+
# Generate statistics
|
|
376
|
+
analyzer = DataStatsAnalyzer()
|
|
377
|
+
stats = analyzer.generate_stats(data)
|
|
378
|
+
|
|
379
|
+
# Print formatted summary
|
|
380
|
+
analyzer.print_summary(data, detailed=True)
|
|
381
|
+
|
|
382
|
+
# Or use convenience function
|
|
383
|
+
stats = generate_stats(data)
|
|
384
|
+
print(f"Total values: {stats['total_values']}")
|
|
385
|
+
print(f"Max depth: {stats['max_depth']}")
|
|
386
|
+
print(f"Complexity: {stats['computed_insights']['complexity_score']}")
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Visualization
|
|
390
|
+
|
|
391
|
+
```python
|
|
392
|
+
from json_explorer import JSONVisualizer, visualize_json
|
|
393
|
+
|
|
394
|
+
# Create visualizer
|
|
395
|
+
visualizer = JSONVisualizer()
|
|
396
|
+
|
|
397
|
+
# Terminal visualization
|
|
398
|
+
visualizer.visualize(data, output="terminal", detailed=True)
|
|
399
|
+
|
|
400
|
+
# HTML visualization
|
|
401
|
+
visualizer.visualize(
|
|
402
|
+
data,
|
|
403
|
+
output="html",
|
|
404
|
+
save_path="report.html",
|
|
405
|
+
detailed=True,
|
|
406
|
+
open_browser=True
|
|
407
|
+
)
|
|
408
|
+
|
|
409
|
+
# Or use convenience function
|
|
410
|
+
visualize_json(data, output="html", detailed=True)
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
### Tree Display
|
|
414
|
+
|
|
415
|
+
```python
|
|
416
|
+
from json_explorer import print_json_analysis, print_compact_tree
|
|
417
|
+
|
|
418
|
+
# Full analysis with tree
|
|
419
|
+
print_json_analysis(data, source="API Response", show_raw=False)
|
|
420
|
+
|
|
421
|
+
# Compact tree (no annotations)
|
|
422
|
+
print_compact_tree(data, source="Config File")
|
|
423
|
+
|
|
424
|
+
# Custom tree builder
|
|
425
|
+
from json_explorer.tree_view import JsonTreeBuilder
|
|
426
|
+
|
|
427
|
+
builder = JsonTreeBuilder(show_conflicts=True, show_optional=True)
|
|
428
|
+
# ... use builder for custom visualization
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
### Code Generation
|
|
432
|
+
|
|
433
|
+
```python
|
|
434
|
+
from json_explorer.codegen import (
|
|
435
|
+
quick_generate,
|
|
436
|
+
generate_from_analysis,
|
|
437
|
+
create_config,
|
|
438
|
+
list_supported_languages,
|
|
439
|
+
get_language_info
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
# Quick generation
|
|
443
|
+
go_code = quick_generate(
|
|
444
|
+
data,
|
|
445
|
+
language="go",
|
|
446
|
+
package_name="models",
|
|
447
|
+
root_name="User"
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
python_code = quick_generate(
|
|
451
|
+
data,
|
|
452
|
+
language="python",
|
|
453
|
+
style="pydantic",
|
|
454
|
+
package_name="models"
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
# Detailed workflow
|
|
458
|
+
analysis = analyze_json(data)
|
|
459
|
+
config = create_config(
|
|
460
|
+
language="go",
|
|
461
|
+
package_name="api",
|
|
462
|
+
add_comments=True,
|
|
463
|
+
language_config={
|
|
464
|
+
"use_pointers_for_optional": True,
|
|
465
|
+
"int_type": "int64"
|
|
466
|
+
}
|
|
467
|
+
)
|
|
468
|
+
|
|
469
|
+
result = generate_from_analysis(analysis, "go", config, "User")
|
|
470
|
+
if result.success:
|
|
471
|
+
print(result.code)
|
|
472
|
+
with open("models.go", "w") as f:
|
|
473
|
+
f.write(result.code)
|
|
474
|
+
else:
|
|
475
|
+
print(f"Error: {result.error_message}")
|
|
476
|
+
|
|
477
|
+
# Discover capabilities
|
|
478
|
+
languages = list_supported_languages()
|
|
479
|
+
print(f"Supported: {languages}")
|
|
480
|
+
|
|
481
|
+
info = get_language_info("python")
|
|
482
|
+
print(f"Python styles: {info.get('styles', [])}")
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
### Interactive Mode
|
|
486
|
+
|
|
487
|
+
```python
|
|
488
|
+
from json_explorer import InteractiveHandler
|
|
489
|
+
|
|
490
|
+
handler = InteractiveHandler()
|
|
491
|
+
handler.set_data(data, source="my_data.json")
|
|
492
|
+
exit_code = handler.run() # Launches interactive UI
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
---
|
|
496
|
+
|
|
497
|
+
## Configuration
|
|
498
|
+
|
|
499
|
+
### Configuration File Format
|
|
500
|
+
|
|
501
|
+
JSON Explorer uses JSON configuration files for code generation:
|
|
502
|
+
|
|
503
|
+
```json
|
|
504
|
+
{
|
|
505
|
+
"package_name": "models",
|
|
506
|
+
"add_comments": true,
|
|
507
|
+
"struct_case": "pascal",
|
|
508
|
+
"field_case": "snake",
|
|
509
|
+
"generate_json_tags": true,
|
|
510
|
+
"json_tag_omitempty": true,
|
|
511
|
+
"language_config": {
|
|
512
|
+
"use_pointers_for_optional": true,
|
|
513
|
+
"int_type": "int64",
|
|
514
|
+
"float_type": "float64"
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### Language-Specific Examples
|
|
520
|
+
|
|
521
|
+
#### Go Configuration
|
|
522
|
+
|
|
523
|
+
```json
|
|
524
|
+
{
|
|
525
|
+
"package_name": "api",
|
|
526
|
+
"add_comments": true,
|
|
527
|
+
"generate_json_tags": true,
|
|
528
|
+
"json_tag_omitempty": true,
|
|
529
|
+
"json_tag_case": "snake",
|
|
530
|
+
"struct_case": "pascal",
|
|
531
|
+
"field_case": "pascal",
|
|
532
|
+
"language_config": {
|
|
533
|
+
"use_pointers_for_optional": true,
|
|
534
|
+
"int_type": "int64",
|
|
535
|
+
"float_type": "float64"
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
#### Python Dataclass Configuration
|
|
541
|
+
|
|
542
|
+
```json
|
|
543
|
+
{
|
|
544
|
+
"package_name": "models",
|
|
545
|
+
"add_comments": true,
|
|
546
|
+
"struct_case": "pascal",
|
|
547
|
+
"field_case": "snake",
|
|
548
|
+
"language_config": {
|
|
549
|
+
"style": "dataclass",
|
|
550
|
+
"dataclass_slots": true,
|
|
551
|
+
"dataclass_frozen": false,
|
|
552
|
+
"dataclass_kw_only": false,
|
|
553
|
+
"use_optional": true
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
#### Python Pydantic Configuration
|
|
559
|
+
|
|
560
|
+
```json
|
|
561
|
+
{
|
|
562
|
+
"package_name": "models",
|
|
563
|
+
"add_comments": true,
|
|
564
|
+
"struct_case": "pascal",
|
|
565
|
+
"field_case": "snake",
|
|
566
|
+
"language_config": {
|
|
567
|
+
"style": "pydantic",
|
|
568
|
+
"pydantic_use_field": true,
|
|
569
|
+
"pydantic_use_alias": true,
|
|
570
|
+
"pydantic_config_dict": true,
|
|
571
|
+
"pydantic_extra_forbid": false,
|
|
572
|
+
"use_optional": true
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
Load configuration:
|
|
578
|
+
|
|
579
|
+
```bash
|
|
580
|
+
json_explorer data.json --generate go --config go_config.json
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
```python
|
|
584
|
+
from json_explorer.codegen import load_config, generate_from_analysis
|
|
585
|
+
|
|
586
|
+
config = load_config("go_config.json")
|
|
587
|
+
result = generate_from_analysis(analysis, "go", config, "User")
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
---
|
|
591
|
+
|
|
592
|
+
## Architecture
|
|
593
|
+
|
|
594
|
+
### Project Structure
|
|
595
|
+
|
|
596
|
+
```
|
|
597
|
+
json_explorer/
|
|
598
|
+
├── __init__.py # Public API exports
|
|
599
|
+
├── __main__.py # Entry point for `python -m json_explorer`
|
|
600
|
+
├── main.py # CLI application coordinator
|
|
601
|
+
├── cli.py # CLI command handler
|
|
602
|
+
├── interactive.py # Interactive mode handler
|
|
603
|
+
│
|
|
604
|
+
├── analyzer.py # JSON structure analysis
|
|
605
|
+
├── search.py # JMESPath-based search
|
|
606
|
+
├── stats.py # Statistical analysis
|
|
607
|
+
├── tree_view.py # Tree visualization
|
|
608
|
+
├── visualizer.py # Multi-format charts (Plotly/curses)
|
|
609
|
+
├── utils.py # File/URL loading utilities
|
|
610
|
+
├── logging_config.py # Centralized logging
|
|
611
|
+
│
|
|
612
|
+
└── codegen/
|
|
613
|
+
├── __init__.py # Code generation API
|
|
614
|
+
├── registry.py # Generator registry system
|
|
615
|
+
├── cli_integration.py # CLI integration
|
|
616
|
+
├── interactive.py # Interactive codegen UI
|
|
617
|
+
│
|
|
618
|
+
├── core/ # Core codegen infrastructure
|
|
619
|
+
│ ├── naming.py # Naming convention system
|
|
620
|
+
│ ├── config.py # Configuration management
|
|
621
|
+
│ ├── templates.py # Template engine
|
|
622
|
+
│ ├── schema.py # Internal schema representation
|
|
623
|
+
│ └── generator.py # Base generator interface
|
|
624
|
+
│
|
|
625
|
+
└── languages/ # Language-specific generators
|
|
626
|
+
├── go/
|
|
627
|
+
│ ├── generator.py
|
|
628
|
+
│ ├── config.py
|
|
629
|
+
│ ├── naming.py
|
|
630
|
+
│ ├── interactive.py
|
|
631
|
+
│ └── templates/ # Jinja2 templates
|
|
632
|
+
│
|
|
633
|
+
└── python/
|
|
634
|
+
├── generator.py
|
|
635
|
+
├── config.py
|
|
636
|
+
├── naming.py
|
|
637
|
+
├── interactive.py
|
|
638
|
+
└── templates/ # Jinja2 templates
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
### Key Design Patterns
|
|
642
|
+
|
|
643
|
+
- **Registry Pattern**: Extensible generator system
|
|
644
|
+
- **Template Method**: Base generator defines workflow
|
|
645
|
+
- **Strategy Pattern**: Multiple naming conventions and styles
|
|
646
|
+
- **Factory Pattern**: Generator creation and configuration
|
|
647
|
+
- **Builder Pattern**: Schema construction from analysis
|
|
648
|
+
|
|
649
|
+
---
|
|
650
|
+
|
|
651
|
+
## Testing
|
|
652
|
+
|
|
653
|
+
Run the test suite:
|
|
654
|
+
|
|
655
|
+
```bash
|
|
656
|
+
pytest
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
Run with coverage:
|
|
660
|
+
|
|
661
|
+
```bash
|
|
662
|
+
pytest --cov=json_explorer --cov-report=html
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
Test categories:
|
|
666
|
+
|
|
667
|
+
- **Core modules**: analyzer, search, stats, tree_view, visualizer
|
|
668
|
+
- **Codegen core**: naming, schema, config, templates
|
|
669
|
+
- **Generators**: Go and Python (all styles)
|
|
670
|
+
- **Integration**: End-to-end workflows
|
|
671
|
+
- **Edge cases**: None handling, conflicts, deep nesting
|
|
672
|
+
|
|
673
|
+
---
|
|
674
|
+
|
|
675
|
+
## Supported Languages
|
|
676
|
+
|
|
677
|
+
| Language | Status | Features |
|
|
678
|
+
| -------------- | --------------- | -------------------------------------------------------- |
|
|
679
|
+
| **Go** | ✅ Full Support | Structs, JSON tags, pointers, customizable type mappings |
|
|
680
|
+
| **Python** | ✅ Full Support | Dataclasses, Pydantic v2, TypedDict, modern type hints |
|
|
681
|
+
| **TypeScript** | 🚧 Coming Soon | Interfaces, types, optional properties |
|
|
682
|
+
| **Rust** | 🚧 Coming Soon | Structs, Serde annotations, Option types |
|
|
683
|
+
|
|
684
|
+
---
|
|
685
|
+
|
|
686
|
+
## Documentation
|
|
687
|
+
|
|
688
|
+
- **API Documentation**: [https://ms-32154.github.io/py-json-analyzer/](https://ms-32154.github.io/py-json-analyzer/)
|
|
689
|
+
- **GitHub Repository**: [https://github.com/MS-32154/py-json-analyzer](https://github.com/MS-32154/py-json-analyzer)
|
|
690
|
+
- **Issue Tracker**: [https://github.com/MS-32154/py-json-analyzer/issues](https://github.com/MS-32154/py-json-analyzer/issues)
|
|
691
|
+
|
|
692
|
+
---
|
|
693
|
+
|
|
694
|
+
## Contributing
|
|
695
|
+
|
|
696
|
+
Contributions are welcome! Here's how to get started:
|
|
697
|
+
|
|
698
|
+
1. **Fork** the repository
|
|
699
|
+
2. **Clone** your fork: `git clone https://github.com/YOUR_USERNAME/py-json-analyzer`
|
|
700
|
+
3. **Create** a feature branch: `git checkout -b feature/amazing-feature`
|
|
701
|
+
4. **Make** your changes and add tests
|
|
702
|
+
5. **Run** tests: `pytest`
|
|
703
|
+
6. **Commit**: `git commit -m 'Add amazing feature'`
|
|
704
|
+
7. **Push**: `git push origin feature/amazing-feature`
|
|
705
|
+
8. **Open** a Pull Request
|
|
706
|
+
|
|
707
|
+
### Development Setup
|
|
708
|
+
|
|
709
|
+
```bash
|
|
710
|
+
# Clone and setup
|
|
711
|
+
git clone https://github.com/MS-32154/py-json-analyzer
|
|
712
|
+
cd py-json-analyzer
|
|
713
|
+
pip install -e ".[dev]"
|
|
714
|
+
|
|
715
|
+
# Run tests
|
|
716
|
+
pytest
|
|
717
|
+
|
|
718
|
+
# Format code
|
|
719
|
+
black json_explorer/
|
|
720
|
+
isort json_explorer/
|
|
721
|
+
|
|
722
|
+
# Type checking (if using mypy)
|
|
723
|
+
mypy json_explorer/
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
### Adding a New Language Generator
|
|
727
|
+
|
|
728
|
+
1. Create `json_explorer/codegen/languages/yourlang/`
|
|
729
|
+
2. Implement `generator.py` extending `CodeGenerator`
|
|
730
|
+
3. Create templates in `templates/`
|
|
731
|
+
4. Register in `json_explorer/codegen/languages/__init__.py`
|
|
732
|
+
5. Add tests in `tests/codegen/languages/test_yourlang.py`
|
|
733
|
+
|
|
734
|
+
---
|
|
735
|
+
|
|
736
|
+
## Support
|
|
737
|
+
|
|
738
|
+
### Getting Help
|
|
739
|
+
|
|
740
|
+
- **Documentation**: Check the [API docs](https://ms-32154.github.io/py-json-analyzer/)
|
|
741
|
+
- **Examples**: See the examples section above
|
|
742
|
+
- **Issues**: [GitHub Issues](https://github.com/MS-32154/py-json-analyzer/issues)
|
|
743
|
+
|
|
744
|
+
### Reporting Issues
|
|
745
|
+
|
|
746
|
+
When reporting issues, please include:
|
|
747
|
+
|
|
748
|
+
1. **Python version**: `python --version`
|
|
749
|
+
2. **Package version**: `pip show py-json-analyzer`
|
|
750
|
+
3. **Operating system**
|
|
751
|
+
4. **Minimal reproducible example**
|
|
752
|
+
5. **Full error traceback**
|
|
753
|
+
6. **Expected vs actual behavior**
|
|
754
|
+
|
|
755
|
+
### Feature Requests
|
|
756
|
+
|
|
757
|
+
We welcome feature requests! Please open an issue with:
|
|
758
|
+
|
|
759
|
+
- Clear description of the feature
|
|
760
|
+
- Use cases and benefits
|
|
761
|
+
- Example of how it would work
|
|
762
|
+
- Any relevant mockups or examples
|
|
763
|
+
|
|
764
|
+
---
|
|
765
|
+
|
|
766
|
+
## License
|
|
767
|
+
|
|
768
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
769
|
+
|
|
770
|
+
---
|
|
771
|
+
|
|
772
|
+
## Acknowledgments
|
|
773
|
+
|
|
774
|
+
- **JMESPath**: Powerful JSON query language
|
|
775
|
+
- **Rich**: Beautiful terminal formatting
|
|
776
|
+
- **Plotly**: Interactive visualizations
|
|
777
|
+
- **Jinja2**: Flexible template engine
|
|
778
|
+
|
|
779
|
+
---
|
|
780
|
+
|
|
781
|
+
## Author
|
|
782
|
+
|
|
783
|
+
**MS-32154**
|
|
784
|
+
|
|
785
|
+
- GitHub: [@MS-32154](https://github.com/MS-32154)
|
|
786
|
+
- Email: msttoffg@gmail.com
|
|
787
|
+
|
|
788
|
+
---
|
|
789
|
+
|
|
790
|
+
**JSON Explorer** – © 2025 MS-32154. All rights reserved.
|