json-lint-tools


Namejson-lint-tools JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/mathewmoon/json-linter
SummaryLints, formats, and diffs JSON files
upload_time2024-01-09 22:24:36
maintainer
docs_urlNone
authorMathew Moon
requires_python>=3.11,<4.0
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # json-lint-tools
Provides linting, diffing and formatting JSON. Diffing and linting is done by comparing an input (file or stdin) to what would be produced by
loading the string with `json.load(data)` then dumping it again with `json.dumps(data)` with options to order keys, order items in arrays, and
specify the expected indentation. The CLI tool can optionally update the original file with the pretty formatted JSON output.


## This package is primarily intended as a CLI tool for linting and formatting JSON. Thereis however documentation for the API [HERE](https://mathewmoon.github.io/json-lint-tools/)


## Installation
```shell
pip install json-lint-tools
```


## CLI Usage
```
usage: jsonfmt [-h] [--check] [-d] [-f] [-i INDENT] [--no-color] [-r] [-s] [--sort-arrays] [--sort-keys] [--stdin] [path ...]

positional arguments:
  path                  Path to a single file or directory of JSON files

options:
  -h, --help            show this help message and exit
  --check               Only check if the files would be changed. Show a list of any files that would be changed and exit with an error if any would be
  -d, --diff            Show a diff
  -f, --format          Format non-conforming files
  -i INDENT, --indent INDENT
                        How many spaces are expected per indentation
  --no-color            Don't print colors to stdout
  -r, --recursive       Search recursively for JSON files
  -s, --sort            Sort all objects by key and all arrays alphabetically. Shorthand for --sort-keys + --sort-arrays
  --sort-arrays         Sort arrays alphabetically
  --sort-keys           Sort keys in JSON objects alphabetically
  --stdin               Read data from stdin instead of a file
```

## Examples
Getting a pretty diff:
```shell
> jsonfmt -r -d tests/jsonfiles                                                                                                                                                                             File: tests/jsonfiles/test.json
---
+++
@@ -6,9 +6,9 @@
   ],
   "baz": {
     "myarry": [
-        "b",
-        "d",
-        "a"
+      "b",
+      "d",
+      "a"
     ]
   }
 }
File: tests/jsonfiles/root_array.json
---
+++
@@ -1 +1,8 @@
-["a", "d", "b", {"foo": "bar"}]
+[
+  "a",
+  "d",
+  "b",
+  {
+    "foo": "bar"
+  }
+]
File: tests/jsonfiles/one_line_obj.json
---
+++
@@ -1 +1,4 @@
-{"foo": "bar", "bar": "baz"}
+{
+  "foo": "bar",
+  "bar": "baz"
+}

```

Formatting stdin:

```shell
> echo '{"foo": "bar"}' | jsonfmt
{
  "foo": "bar"
}
```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mathewmoon/json-linter",
    "name": "json-lint-tools",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Mathew Moon",
    "author_email": "me@mathewmoon.net",
    "download_url": "https://files.pythonhosted.org/packages/09/18/31e80c46d1fdf632a181725c5fe96850a22124dc21c0b3c1670395e6b321/json_lint_tools-0.1.2.tar.gz",
    "platform": null,
    "description": "# json-lint-tools\nProvides linting, diffing and formatting JSON. Diffing and linting is done by comparing an input (file or stdin) to what would be produced by\nloading the string with `json.load(data)` then dumping it again with `json.dumps(data)` with options to order keys, order items in arrays, and\nspecify the expected indentation. The CLI tool can optionally update the original file with the pretty formatted JSON output.\n\n\n## This package is primarily intended as a CLI tool for linting and formatting JSON. Thereis however documentation for the API [HERE](https://mathewmoon.github.io/json-lint-tools/)\n\n\n## Installation\n```shell\npip install json-lint-tools\n```\n\n\n## CLI Usage\n```\nusage: jsonfmt [-h] [--check] [-d] [-f] [-i INDENT] [--no-color] [-r] [-s] [--sort-arrays] [--sort-keys] [--stdin] [path ...]\n\npositional arguments:\n  path                  Path to a single file or directory of JSON files\n\noptions:\n  -h, --help            show this help message and exit\n  --check               Only check if the files would be changed. Show a list of any files that would be changed and exit with an error if any would be\n  -d, --diff            Show a diff\n  -f, --format          Format non-conforming files\n  -i INDENT, --indent INDENT\n                        How many spaces are expected per indentation\n  --no-color            Don't print colors to stdout\n  -r, --recursive       Search recursively for JSON files\n  -s, --sort            Sort all objects by key and all arrays alphabetically. Shorthand for --sort-keys + --sort-arrays\n  --sort-arrays         Sort arrays alphabetically\n  --sort-keys           Sort keys in JSON objects alphabetically\n  --stdin               Read data from stdin instead of a file\n```\n\n## Examples\nGetting a pretty diff:\n```shell\n> jsonfmt -r -d tests/jsonfiles                                                                                                                                                                         \ue0b2 \ue0a0   File: tests/jsonfiles/test.json\n---\n+++\n@@ -6,9 +6,9 @@\n   ],\n   \"baz\": {\n     \"myarry\": [\n-        \"b\",\n-        \"d\",\n-        \"a\"\n+      \"b\",\n+      \"d\",\n+      \"a\"\n     ]\n   }\n }\nFile: tests/jsonfiles/root_array.json\n---\n+++\n@@ -1 +1,8 @@\n-[\"a\", \"d\", \"b\", {\"foo\": \"bar\"}]\n+[\n+  \"a\",\n+  \"d\",\n+  \"b\",\n+  {\n+    \"foo\": \"bar\"\n+  }\n+]\nFile: tests/jsonfiles/one_line_obj.json\n---\n+++\n@@ -1 +1,4 @@\n-{\"foo\": \"bar\", \"bar\": \"baz\"}\n+{\n+  \"foo\": \"bar\",\n+  \"bar\": \"baz\"\n+}\n\n```\n\nFormatting stdin:\n\n```shell\n> echo '{\"foo\": \"bar\"}' | jsonfmt\n{\n  \"foo\": \"bar\"\n}\n```",
    "bugtrack_url": null,
    "license": "",
    "summary": "Lints, formats, and diffs JSON files",
    "version": "0.1.2",
    "project_urls": {
        "Documentation": "https://github.com/mathewmoon/json-linter",
        "Homepage": "https://github.com/mathewmoon/json-linter"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "23dffec729fae16a4205eeb0196a8b1b4931faa6396c3c05ef987d75a6bd7afc",
                "md5": "4bbf3702c45cbf59004591a75380a029",
                "sha256": "846d7900dea0e2fcab4554c811da8b27457b0694e0d176c400af7c8c80981504"
            },
            "downloads": -1,
            "filename": "json_lint_tools-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4bbf3702c45cbf59004591a75380a029",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11,<4.0",
            "size": 6049,
            "upload_time": "2024-01-09T22:24:35",
            "upload_time_iso_8601": "2024-01-09T22:24:35.947291Z",
            "url": "https://files.pythonhosted.org/packages/23/df/fec729fae16a4205eeb0196a8b1b4931faa6396c3c05ef987d75a6bd7afc/json_lint_tools-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "091831e80c46d1fdf632a181725c5fe96850a22124dc21c0b3c1670395e6b321",
                "md5": "464d255454d144e69a7aa79f044d6238",
                "sha256": "74be18623497a6aef17fc108feb740a5ceabe84191bf489c6dd3733291f5920d"
            },
            "downloads": -1,
            "filename": "json_lint_tools-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "464d255454d144e69a7aa79f044d6238",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11,<4.0",
            "size": 4902,
            "upload_time": "2024-01-09T22:24:36",
            "upload_time_iso_8601": "2024-01-09T22:24:36.926449Z",
            "url": "https://files.pythonhosted.org/packages/09/18/31e80c46d1fdf632a181725c5fe96850a22124dc21c0b3c1670395e6b321/json_lint_tools-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-09 22:24:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mathewmoon",
    "github_project": "json-linter",
    "github_not_found": true,
    "lcname": "json-lint-tools"
}
        
Elapsed time: 0.53802s