jsonstat-validator 0.1.0__py3-none-any.whl

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.
Files changed (51) hide show
  1. jsonstat_validator/__init__.py +34 -0
  2. jsonstat_validator/tests/__init__.py +1 -0
  3. jsonstat_validator/tests/conftest.py +10 -0
  4. jsonstat_validator/tests/custom_tests.py +411 -0
  5. jsonstat_validator/tests/samples/areas/canada.json +16 -0
  6. jsonstat_validator/tests/samples/areas/galicia.json +16 -0
  7. jsonstat_validator/tests/samples/areas/index.json +31 -0
  8. jsonstat_validator/tests/samples/areas/oecd.json +16 -0
  9. jsonstat_validator/tests/samples/areas/us.json +26 -0
  10. jsonstat_validator/tests/samples/canada.json +131 -0
  11. jsonstat_validator/tests/samples/datasets/index.json +51 -0
  12. jsonstat_validator/tests/samples/galicia.json +124 -0
  13. jsonstat_validator/tests/samples/hierarchy.json +200 -0
  14. jsonstat_validator/tests/samples/index.json +36 -0
  15. jsonstat_validator/tests/samples/metrics/gdp/gsp.json +16 -0
  16. jsonstat_validator/tests/samples/metrics/gdp/gsppc.json +16 -0
  17. jsonstat_validator/tests/samples/metrics/gdp/gspw.json +16 -0
  18. jsonstat_validator/tests/samples/metrics/gdp/index.json +26 -0
  19. jsonstat_validator/tests/samples/metrics/index.json +26 -0
  20. jsonstat_validator/tests/samples/metrics/lfs/employed.json +16 -0
  21. jsonstat_validator/tests/samples/metrics/lfs/index.json +31 -0
  22. jsonstat_validator/tests/samples/metrics/lfs/lf.json +16 -0
  23. jsonstat_validator/tests/samples/metrics/lfs/unemployed.json +16 -0
  24. jsonstat_validator/tests/samples/metrics/lfs/unr.json +21 -0
  25. jsonstat_validator/tests/samples/metrics/pop/index.json +21 -0
  26. jsonstat_validator/tests/samples/metrics/pop/pop.json +26 -0
  27. jsonstat_validator/tests/samples/metrics/pop/popw.json +16 -0
  28. jsonstat_validator/tests/samples/oecd.json +170 -0
  29. jsonstat_validator/tests/samples/order.json +38 -0
  30. jsonstat_validator/tests/samples/sources/bls.json +21 -0
  31. jsonstat_validator/tests/samples/sources/ige.json +16 -0
  32. jsonstat_validator/tests/samples/sources/index.json +41 -0
  33. jsonstat_validator/tests/samples/sources/jsonstat.json +21 -0
  34. jsonstat_validator/tests/samples/sources/oecd.json +16 -0
  35. jsonstat_validator/tests/samples/sources/statcan.json +16 -0
  36. jsonstat_validator/tests/samples/sources/wikipedia.json +16 -0
  37. jsonstat_validator/tests/samples/topics/accounts.json +16 -0
  38. jsonstat_validator/tests/samples/topics/demos.json +21 -0
  39. jsonstat_validator/tests/samples/topics/index.json +31 -0
  40. jsonstat_validator/tests/samples/topics/labor.json +26 -0
  41. jsonstat_validator/tests/samples/topics/population.json +26 -0
  42. jsonstat_validator/tests/samples/us-gsp.json +230 -0
  43. jsonstat_validator/tests/samples/us-labor.json +6509 -0
  44. jsonstat_validator/tests/samples/us-unr.json +3269 -0
  45. jsonstat_validator/tests/test_official_samples.py +51 -0
  46. jsonstat_validator/validator.py +608 -0
  47. jsonstat_validator-0.1.0.dist-info/LICENSE +21 -0
  48. jsonstat_validator-0.1.0.dist-info/METADATA +196 -0
  49. jsonstat_validator-0.1.0.dist-info/RECORD +51 -0
  50. jsonstat_validator-0.1.0.dist-info/WHEEL +5 -0
  51. jsonstat_validator-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,196 @@
1
+ Metadata-Version: 2.2
2
+ Name: jsonstat-validator
3
+ Version: 0.1.0
4
+ Summary: A Python validator for the JSON-stat 2.0 standard format, based on Pydantic.
5
+ Home-page: https://github.com/ahmed-hassan19/jsonstat-validator
6
+ Author: Ahmed Hassan
7
+ Author-email: Ahmed Hassan <ahmedhassan.ahmed@fao.org>
8
+ License: # MIT License
9
+
10
+ Copyright (c) 2025 JSON-stat Validator Contributors
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+
30
+ Project-URL: Homepage, https://github.com/ahmed-hassan19/jsonstat-validator
31
+ Project-URL: Bug Tracker, https://github.com/ahmed-hassan19/jsonstat-validator/issues
32
+ Project-URL: Documentation, https://github.com/ahmed-hassan19/jsonstat-validator#readme
33
+ Keywords: json-stat,validator,json,data-engineering,pydantic,python,fao
34
+ Classifier: Programming Language :: Python :: 3
35
+ Classifier: Programming Language :: Python :: 3.8
36
+ Classifier: Programming Language :: Python :: 3.9
37
+ Classifier: Programming Language :: Python :: 3.10
38
+ Classifier: Programming Language :: Python :: 3.11
39
+ Classifier: Programming Language :: Python :: 3.12
40
+ Classifier: License :: OSI Approved :: MIT License
41
+ Classifier: Operating System :: OS Independent
42
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
43
+ Classifier: Topic :: Software Development :: Quality Assurance
44
+ Requires-Python: >=3.8
45
+ Description-Content-Type: text/markdown
46
+ License-File: LICENSE
47
+ Requires-Dist: pydantic<3.0.0,>=2.0.0
48
+ Provides-Extra: dev
49
+ Requires-Dist: pytest>=8.1.1; extra == "dev"
50
+ Requires-Dist: build>=1.0.0; extra == "dev"
51
+ Requires-Dist: twine>=4.0.0; extra == "dev"
52
+ Dynamic: author
53
+ Dynamic: home-page
54
+ Dynamic: requires-python
55
+
56
+ # JSON-stat Validator
57
+
58
+ [![PyPI version](https://badge.fury.io/py/jsonstat-validator.svg)](https://badge.fury.io/py/jsonstat-validator)
59
+ [![Python Version](https://img.shields.io/pypi/pyversions/jsonstat-validator.svg)](https://pypi.org/project/jsonstat-validator/)
60
+ [![License](https://img.shields.io/github/license/ahmed-hassan19/jsonstat-validator.svg)](https://github.com/ahmed-hassan19/jsonstat-validator/blob/main/LICENSE)
61
+
62
+ A Python validator for the JSON-stat 2.0 standard format, based on Pydantic.
63
+
64
+ JSON-stat is a simple lightweight format for data interchange. It is a JSON format for data dissemination that allows the representation of statistical data in a way that is both simple and convenient for data processing. With this validator, you can ensure your data conforms to the official [JSON-stat 2.0 specification](https://json-stat.org/full/).
65
+
66
+ ## Installation
67
+
68
+ ```bash
69
+ pip install jsonstat-validator
70
+ ```
71
+
72
+ ## Usage
73
+
74
+ ### Basic Validation
75
+
76
+ ```python
77
+ import json
78
+ from jsonstat_validator import validate_jsonstat
79
+
80
+ # Load your JSON-stat data
81
+ with open("data.json", "r") as f:
82
+ data = json.load(f)
83
+
84
+ # Validate the data
85
+ try:
86
+ result = validate_jsonstat(data)
87
+ print("Validation successful!")
88
+ except ValueError as e:
89
+ print(f"Validation failed: {e}")
90
+ ```
91
+
92
+ ### Example JSON-stat Dataset
93
+
94
+ Here's a simplified example of a JSON-stat dataset representing unemployment data:
95
+
96
+ ```json
97
+ {
98
+ "version": "2.0",
99
+ "class": "dataset",
100
+ "label": "Unemployment rate sample",
101
+ "source": "Sample data",
102
+ "updated": "2023-01-15",
103
+ "id": ["indicator", "area", "year"],
104
+ "size": [1, 3, 2],
105
+ "value": [5.8, 6.2, 7.1, 7.5, 4.2, 4.9],
106
+ "role": {
107
+ "time": ["year"],
108
+ "geo": ["area"],
109
+ "metric": ["indicator"]
110
+ },
111
+ "dimension": {
112
+ "indicator": {
113
+ "label": "Economic indicator",
114
+ "category": {
115
+ "label": {
116
+ "UNR": "unemployment rate"
117
+ },
118
+ "unit": {
119
+ "UNR": {
120
+ "symbol": "%",
121
+ "decimals": 1
122
+ }
123
+ }
124
+ }
125
+ },
126
+ "year": {
127
+ "label": "Year",
128
+ "category": {
129
+ "index": ["2020", "2021"]
130
+ }
131
+ },
132
+ "area": {
133
+ "label": "Country",
134
+ "category": {
135
+ "index": ["US", "JP", "EU"],
136
+ "label": {
137
+ "US": "United States",
138
+ "JP": "Japan",
139
+ "EU": "European Union"
140
+ }
141
+ }
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+ ## Features
148
+
149
+ - Validates JSON-stat data against the [full 2.0 specification](https://json-stat.org/full).
150
+ - Provides models for all major JSON-stat responses: **Dataset**, **Dimension**, **Collection**.
151
+ - Built on Pydantic for robust type validation and error messages.
152
+ - Provides tests against the [official JSON-stat samples](https://json-stat.org/samples/collection.json) as well as custom fine-grained tests.
153
+
154
+ ## Testing
155
+
156
+ The validator has been thoroughly tested with all official JSON-stat samples from the [JSON-stat website](https://json-stat.org/samples/).
157
+
158
+ To run tests:
159
+
160
+ First, install the development dependencies:
161
+
162
+ ```bash
163
+ pip install jsonstat-validator[dev]
164
+ ```
165
+
166
+ Then run the tests:
167
+
168
+ ```bash
169
+ pytest
170
+ ```
171
+
172
+ To run a specific test file (e.g. test official samples only):
173
+
174
+ ```bash
175
+ pytest tests/test_official_samples.py
176
+ ```
177
+
178
+ ## License
179
+
180
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
181
+
182
+ ## Contributing
183
+
184
+ Contributions are welcome! Please feel free to submit a Pull Request.
185
+
186
+ 1. Fork the repository
187
+ 2. Create your feature branch (`git checkout -b feature/new-feature`)
188
+ 3. Commit your changes (`git commit -m 'Add some new feature'`)
189
+ 4. Push to the branch (`git push origin feature/new-feature`)
190
+ 5. Open a Pull Request
191
+
192
+ ## Credits
193
+
194
+ This package is maintained by Ahmed Hassan ([@ahmed-hassan19](https://github.com/ahmed-hassan19)) and was created for use at the Food and Agriculture Organization (FAO) of the United Nations.
195
+
196
+ The JSON-stat format was created by [Xavier Badosa](https://www.linkedin.com/in/badosa).
@@ -0,0 +1,51 @@
1
+ jsonstat_validator/__init__.py,sha256=wAFP3mKN6XwAPNRygWr_pSHDdKJ6F4Y7sp8sl1C1zuw,691
2
+ jsonstat_validator/validator.py,sha256=i5g57AkanmTMu-B4pUfeuVlXbj3OAdBwGpyFvo3S0Ek,22107
3
+ jsonstat_validator/tests/__init__.py,sha256=5w3FOHjkruZRg3oUSCmYHNKHTmESy3wFPynq05XLb_s,44
4
+ jsonstat_validator/tests/conftest.py,sha256=2UZL2pdcbM1iO2Uv837HPr6csDpIkhbnH_3v5aDDhW0,249
5
+ jsonstat_validator/tests/custom_tests.py,sha256=lJbhOipLEwPJdVHLVg-dTl4Q2cQK9Lkfs2us33qUfo8,14477
6
+ jsonstat_validator/tests/test_official_samples.py,sha256=yRXVqETmVUYNib-nf0odgShbo0Pq5YY4JJCj35KGzf0,1658
7
+ jsonstat_validator/tests/samples/canada.json,sha256=a6eMhLAA6HykWO2t11l5tpz0i6v2zN6izmvpcQbHGrY,3105
8
+ jsonstat_validator/tests/samples/galicia.json,sha256=W6ymWRax14yxAK_778A9kIWXdVV_6R5VLUJH4pv_AZI,22102
9
+ jsonstat_validator/tests/samples/hierarchy.json,sha256=NxvVVWmM5TBBeEdHUkmorh-PoN5D82-m3IIFXJO5UH8,8881
10
+ jsonstat_validator/tests/samples/index.json,sha256=0DjvjTpS8D0IDW8oyHsk3E5hRucnubekAMSflR_Lgyw,893
11
+ jsonstat_validator/tests/samples/oecd.json,sha256=3aRoESyTT4xJQDMljgvF6RXKWCmnirl0_7nNFTT2TPM,10917
12
+ jsonstat_validator/tests/samples/order.json,sha256=2mlvBudHeTiEUHqjPkoO4ZO7ztbwxZ7HiO_YJ1Br-8E,851
13
+ jsonstat_validator/tests/samples/us-gsp.json,sha256=L427DYaM9wq633nQ-ul32NNyPzQ3tBMIKQ_8FJTpojM,4808
14
+ jsonstat_validator/tests/samples/us-labor.json,sha256=lVhVpNQj9E90uLDukxe6cVI1IQRZKtewRAT1gPGK0rg,245081
15
+ jsonstat_validator/tests/samples/us-unr.json,sha256=uz0uwa4a1WwxzJgQCAe3Uh29nYuyN2agLF76UX4Vyzk,77734
16
+ jsonstat_validator/tests/samples/areas/canada.json,sha256=7wU11arz_dvX-_svc4B3haC-b1cc7sum69fovxu0aZw,363
17
+ jsonstat_validator/tests/samples/areas/galicia.json,sha256=0Fi3gCcp9HKbQd-kqhbZXg8OZ8eUByZRs3swmQJ3rQ0,405
18
+ jsonstat_validator/tests/samples/areas/index.json,sha256=OnXC6nJodtgIY23dNN4PEgL340t4YAnABcF_gZelGI0,745
19
+ jsonstat_validator/tests/samples/areas/oecd.json,sha256=eUGD5KjgNvbIJdyg4S7LJSUZehUKIcmfE7DM0fLZO1k,366
20
+ jsonstat_validator/tests/samples/areas/us.json,sha256=5voj9CXI91w0CM2zIzfJNEXBmhaxupRZcQrLUzptdWU,682
21
+ jsonstat_validator/tests/samples/datasets/index.json,sha256=upGVvsV0VvBV0UM0DyUvxUUwOG4DBBnvR2kb6KYqaS4,1525
22
+ jsonstat_validator/tests/samples/metrics/index.json,sha256=33CQfmS-f6pzvNqgBpRI4daCGu8L6GCJ-A4jcQSuYq0,684
23
+ jsonstat_validator/tests/samples/metrics/gdp/gsp.json,sha256=SbrOZurhvS-CxraYnVZqN293yQh2I9pAputsM4o25Yo,367
24
+ jsonstat_validator/tests/samples/metrics/gdp/gsppc.json,sha256=HHqqIS4JVOYD7206a9dUUucZbHcRqmgUt_xP0WXlRvk,380
25
+ jsonstat_validator/tests/samples/metrics/gdp/gspw.json,sha256=_P5hzfWmMUg9msznHcYBl-0_0Hg3A3AaRC79Qk7CqJ0,398
26
+ jsonstat_validator/tests/samples/metrics/gdp/index.json,sha256=JXd2_VRpAm8X_Z6twnqFTUplXxtfHQLEFAdys549guM,738
27
+ jsonstat_validator/tests/samples/metrics/lfs/employed.json,sha256=VmngzssIpzuyNAKboH7wf2197i7XxtwaotOcNMAQi-0,380
28
+ jsonstat_validator/tests/samples/metrics/lfs/index.json,sha256=sZ28CZOTEl0Py0Gfe6wiMmBkVxZdeGQq4OchpxprSmE,825
29
+ jsonstat_validator/tests/samples/metrics/lfs/lf.json,sha256=ScaE824vHG6Q7T23IMtCt9NnpJNmcsSt2LGN_b7XBvg,377
30
+ jsonstat_validator/tests/samples/metrics/lfs/unemployed.json,sha256=bVmWBE5-XcuRIzON1M0XMb_GPxBSkR3CbGQ79sMCqI4,384
31
+ jsonstat_validator/tests/samples/metrics/lfs/unr.json,sha256=lUKMphIFxbZlnduyHCt04q8DJKBZen2l2L2fK0qXE58,549
32
+ jsonstat_validator/tests/samples/metrics/pop/index.json,sha256=llnmomRkIZJWiBstp4yUbbmeMRPZjbte4xxfwRIQ_s8,525
33
+ jsonstat_validator/tests/samples/metrics/pop/pop.json,sha256=FIeNapSq3bD4BBLM48IXTEZXvwk03Fsfm4OozQLzpCM,718
34
+ jsonstat_validator/tests/samples/metrics/pop/popw.json,sha256=GB6PlpnkDrfZfJRyF9pyHtst42Oa19NKyqf2hYBXcJs,387
35
+ jsonstat_validator/tests/samples/sources/bls.json,sha256=Am3nXApblwvZ-WNcjOYN3jSvmYxlhFZfvTwcsCtFtTw,557
36
+ jsonstat_validator/tests/samples/sources/ige.json,sha256=x_ARvi4WomJu3848bZkjxEWNH5FrXZaRu_byiELQM_4,430
37
+ jsonstat_validator/tests/samples/sources/index.json,sha256=uk6UmFT9Pzi6tlMt6rEn3OxQWhYkPJnQ3PInzH_gh4c,1101
38
+ jsonstat_validator/tests/samples/sources/jsonstat.json,sha256=vC8j0Hyt445QKqu-tjhdXhrdSj3jqediKh9egaXIOiY,525
39
+ jsonstat_validator/tests/samples/sources/oecd.json,sha256=vryyWeBjwQsBbvCsYmojbRZ5y0zoL9fj2wPLBseUd20,365
40
+ jsonstat_validator/tests/samples/sources/statcan.json,sha256=ocZuRPZCRCxI-Wv0pi3wgXSDOeppoGPW-14rfVbOAlo,379
41
+ jsonstat_validator/tests/samples/sources/wikipedia.json,sha256=Xs3X4Pw_mXvxi8BfzdwKA4qhu_w47wTMU3NMxXLoBY8,359
42
+ jsonstat_validator/tests/samples/topics/accounts.json,sha256=ReLpG62nfWCHWeev-x-tuxb1anFnIW2utXM-bsEsNZ0,364
43
+ jsonstat_validator/tests/samples/topics/demos.json,sha256=SaKOqgnHvy8zOh7FMqtX7emXhapb0iy-pGGbbLQzHVA,522
44
+ jsonstat_validator/tests/samples/topics/index.json,sha256=1fbgaSXbeIypSASDOn6wJcMg77YenDXUY-QTHg4911k,766
45
+ jsonstat_validator/tests/samples/topics/labor.json,sha256=k270tRO9R_FE9VWJtlClDd9vmbaQuk_DK9VJXnxb1E0,695
46
+ jsonstat_validator/tests/samples/topics/population.json,sha256=OfRTyeMvTgM9HrugypUc0jWHrggSt43QpxCTAW--YUE,719
47
+ jsonstat_validator-0.1.0.dist-info/LICENSE,sha256=cyCvx3tHW8u9ZWGkTMrCKaB2ft4RonlMBVOEHDa2tEk,1091
48
+ jsonstat_validator-0.1.0.dist-info/METADATA,sha256=wzIjL1JHCdUtS5YyvQ4pkBsbC_Q8OXW2kCIHb3efvzM,6675
49
+ jsonstat_validator-0.1.0.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
50
+ jsonstat_validator-0.1.0.dist-info/top_level.txt,sha256=l6xoMFlWGRRbXMxl4MG-q0FA3In7rYZLBzVF8W7IhdU,19
51
+ jsonstat_validator-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (76.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ jsonstat_validator