Skip to content

Instantly share code, notes, and snippets.

@creichert
Last active November 14, 2018 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creichert/fc6cd49ab199384a14987ff69ce476b4 to your computer and use it in GitHub Desktop.
Save creichert/fc6cd49ab199384a14987ff69ce476b4 to your computer and use it in GitHub Desktop.
Validate JSON Schema documents with Org mode

Validate JSON Schema documents with Org mode

  • Validate JSON literals
    #+NAME: org-src-json-schema-literals
    #+BEGIN_SRC shell :results pp
    curl -s https://assertible.com/json -d '{
      "schema": {},
      "json": {}
      }' | jq .
    #+END_SRC
    
    #+RESULTS: org-src-json-schema-literals
    : {
    :   "errors": [],
    :   "valid": true
    : }
    
  • Validating JSON Schema files
    #+NAME: org-src-json-schema-files
    #+BEGIN_SRC shell :results pp
    SCHEMA=$(cat $HOME/api-json-schema.json)
    JSON=$(cat $HOME/api-response-json-schema.json)
    curl -s https://assertible.com/json -d "{
        \"schema\": $SCHEMA,
        \"json\": $JSON
      }" | jq .
    #+END_SRC
    
    #+RESULTS: org-src-json-schema-files
    : {
    :   "errors": [],
    :   "valid": true
    : }
    
  • Good validation errors The Assertible JSON Schema Validation API gives back decent errors too
    #+NAME: org-src-json-schema-errors
    #+BEGIN_SRC shell :results pp
    curl -s https://assertible.com/json -d '{
      "schema": {"type":"object"},
      "json": null
      }' | jq .errors[]
    #+END_SRC
    
    #+RESULTS: org-src-json-schema-errors
    : "failed to validate type - `null` is not a object"
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment