|
| 1 | +# docker-jsonlint |
| 2 | + |
| 3 | +[](https://travis-ci.com/PeterDaveHello/docker-jsonlint) |
| 4 | +[](https://hub.docker.com/r/peterdavehello/jsonlint/) |
| 5 | +[](https://microbadger.com/images/peterdavehello/jsonlint/) |
| 6 | +[](https://hub.docker.com/r/peterdavehello/jsonlint/tags/) |
| 7 | + |
| 8 | +[](https://hub.docker.com/r/peterdavehello/jsonlint/) |
| 9 | + |
| 10 | +Dockerized [jsonlint](https://github.com/zaach/jsonlint) with various versions, easy to use and easy to integrate with CI. |
| 11 | + |
| 12 | +## Table of Contents |
| 13 | + |
| 14 | +- [Usage](#usage) |
| 15 | + - [Command line](#command-line) |
| 16 | + - [Use latest version](#use-latest-version) |
| 17 | + - [Use specific version](#use-specific-version) |
| 18 | + - [Continuous Integration (CI)](#continuous-integration-ci) |
| 19 | + - [Travis CI](#travis-ci) |
| 20 | + - [GitLab CI](#gitlab-ci) |
| 21 | +- [jsonlint cli usage](#jsonlint-cli-usage) |
| 22 | +- [Build](#build) |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +### Command line |
| 27 | + |
| 28 | +#### Use latest version |
| 29 | + |
| 30 | +```sh |
| 31 | +docker run --rm -v $PATH_TO_JSON:/json peterdavehello/jsonlint jsonlint -q JSON_FILE.json |
| 32 | + |
| 33 | +# Please replace "$PATH_TO_JSON" with your custom path, |
| 34 | +# and replace "JSON_FILE.json" with your real json file filename. |
| 35 | +``` |
| 36 | + |
| 37 | +#### Use specific version |
| 38 | + |
| 39 | +Just like above, but you can specify version of jsonlint, for example: |
| 40 | + |
| 41 | +```sh |
| 42 | +docker run --rm -v $PATH_TO_JSON:/json peterdavehello/jsonlint:1.6.3 jsonlint -q JSON_FILE.json |
| 43 | + |
| 44 | +# Please replace "1.6.3" with the version number you want. |
| 45 | +# Don't forget to replace "$PATH_TO_JSON" & "JSON_FILE.json". |
| 46 | +``` |
| 47 | + |
| 48 | +### Continuous Integration (CI) |
| 49 | + |
| 50 | +#### Travis CI |
| 51 | + |
| 52 | +Enable Docker service in your `.travis.yml`: |
| 53 | + |
| 54 | +```yaml |
| 55 | +services: |
| 56 | + - docker |
| 57 | +``` |
| 58 | +
|
| 59 | +And use the same command in the `scripts` part as the command line mentions, for example: |
| 60 | + |
| 61 | +```yaml |
| 62 | +services: |
| 63 | + - docker |
| 64 | +
|
| 65 | +scripts: |
| 66 | + - docker run --rm -v $TRAVIS_BUILD_DIR:/json peterdavehello/jsonlint:1.6.3 jsonlint -q example.json |
| 67 | +``` |
| 68 | + |
| 69 | +This will lint a example json file called `example.json` |
| 70 | + |
| 71 | +#### GitLab CI |
| 72 | + |
| 73 | +Add this block to your `.gitlab-ci.yml`: |
| 74 | + |
| 75 | +```yaml |
| 76 | +jsonlint: |
| 77 | + stage: lint |
| 78 | + variables: |
| 79 | + jsonlint_version: "1.6.3" |
| 80 | + image: peterdavehello/jsonlint:$jsonlint_version |
| 81 | + only: |
| 82 | + changes: |
| 83 | + - "**/*.json" |
| 84 | + script: |
| 85 | + - find . -name "*.json" | xargs -n 1 jsonlint -q |
| 86 | +``` |
| 87 | + |
| 88 | +Replace "1.6.3" with the version you want to use, you can also use "latest" for the very new version. |
| 89 | + |
| 90 | +## jsonlint cli usage |
| 91 | + |
| 92 | +Just pass `-h`/`--help` to jsonlint to get its help message, for example: |
| 93 | + |
| 94 | +```sh |
| 95 | +$ docker run --rm peterdavehello/jsonlint jsonlint --help |
| 96 | +
|
| 97 | +Usage: jsonlint [file] [options] |
| 98 | +
|
| 99 | +file file to parse; otherwise uses stdin |
| 100 | +
|
| 101 | +Options: |
| 102 | + -v, --version print version and exit |
| 103 | + -s, --sort-keys sort object keys |
| 104 | + -i, --in-place overwrite the file |
| 105 | + -t CHAR, --indent CHAR character(s) to use for indentation [ ] |
| 106 | + -c, --compact compact error display |
| 107 | + -V, --validate a JSON schema to use for validation |
| 108 | + -e, --environment which specification of JSON Schema the validation file uses [json-schema-draft-03] |
| 109 | + -q, --quiet do not print the parsed json to STDOUT [false] |
| 110 | +``` |
| 111 | + |
| 112 | +For more details, check out the [jsonlint project](https://github.com/zaach/jsonlint) page. |
| 113 | + |
| 114 | +## Build |
| 115 | + |
| 116 | +Build command, you need to specify a valid jsonlint version argument to `jsonLINT_VERSION`: |
| 117 | + |
| 118 | +```sh |
| 119 | +docker build --build-arg JSONLINT_VERSION="1.6.3" -t docker-jsonlint . |
| 120 | +
|
| 121 | +# Replace "docker-jsonlint" with the preferred image name |
| 122 | +``` |
| 123 | + |
| 124 | +You can find a valid version on [jsonlint](https://www.npmjs.com/package/jsonlint?activeTab=versions) npm registry page, or just poke the [registry](https://registry.npmjs.org/jsonlint) to retrieve more details. |
0 commit comments