adriens / katacoda-glia-labs

https://www.katacoda.com/glialabs
0 stars 2 forks source link

Create new scenario [Json linting with "JSON Lint"] in [DevOPS Tools] #33

Open adriens opened 3 years ago

adriens commented 3 years ago

Requirements

Optional

https://www.npmjs.com/package/jsonlint

HakumenNC commented 3 years ago

Troublecase : when the json contains tabulations :

sample-tabs.json file content

{"message": "json   with    tabulations"}
$ jsonlint /d/sample-tabs.json
Error: Parse error on line 1:
{"message":     "json   with    tabulatio
------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'
    at Object.parseError (C:\Users\rsoutrat\AppData\Roaming\npm\node_modules\jsonlint\lib\jsonlint.js:55:11)
    at Object.parse (C:\Users\rsoutrat\AppData\Roaming\npm\node_modules\jsonlint\lib\jsonlint.js:132:22)
    at parse (C:\Users\rsoutrat\AppData\Roaming\npm\node_modules\jsonlint\lib\cli.js:82:14)
    at main (C:\Users\rsoutrat\AppData\Roaming\npm\node_modules\jsonlint\lib\cli.js:135:14)
    at Object.<anonymous> (C:\Users\rsoutrat\AppData\Roaming\npm\node_modules\jsonlint\lib\cli.js:179:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
adriens commented 3 years ago

While with spaces.json :

{"message": "json with spaces"}

jsonlint -p spaces.json gives :

{
  "message": "json with spaces"
}
adriens commented 3 years ago

Especially talk about the validate option : -V, --validate a JSON schema to use for validation

adriens commented 3 years ago

@HakumenNC @mbarre , vous pouvez dropper ici des fichiers pourris et des bons 🙏 ...avec rien de pas secure

HakumenNC commented 3 years ago

first wave : jsonlint.zip

adriens commented 3 years ago

👏 Excellent, du neuf très bientot

HakumenNC commented 3 years ago

Example with json schema validation :

Good format

$ jsonlint valid.json -V data.schema.json
{
  "uuid": "2a86652f-be53-4be9-9ae6-414b3c78537f",
  "name": "Jean",
  "firstName": "Doe",
  "hobbies": [
    {
      "uuid": "9f5e468a-aa72-4cd0-937d-a0845bd053e4",
      "name": "coding"
    },
    {
      "uuid": "60a7c607-7819-4679-b325-f59233154db8",
      "name": "design"
    },
    {
      "uuid": "9f5e468a-aa72-4cd0-937d-a0845bd053e4",
      "name": "kayak"
    }
  ]
}

Wrong format

$ jsonlint wrong-schema-format.json -V data.schema.json
Validation Errors:

Instance is not a required type
uri: urn:uuid:88abd13c-53f7-4d67-95ea-24e08377ce3d#/name
schemaUri: urn:uuid:5ac07cfe-8ce4-4f4c-90a6-2a8c9befb4c0#/properties/name
attribute: type
details: ["string"]
adriens commented 3 years ago

https://github.com/adriens/json_hall_of_shame

adriens commented 3 years ago

@HakumenNC tu peux dropper ça enissues direct sur la repo du hall of shame ?