项目作者: lisez

项目描述 :
An executable JSON validator with JSON schema to validate documents from local files or databases.
高级语言: Go
项目地址: git://github.com/lisez/clerk.git
创建时间: 2021-02-20T07:34:43Z
项目社区:https://github.com/lisez/clerk

开源协议:MIT License

下载


clerk

An executable JSON validator with JSON schema to validate documents from local files or databases.

Install

  1. git clone git@github.com:lisez/clerk.git
  2. make install
  3. make build

Usage

  1. $ clerk -h
  2. Usage:
  3. clerk [<schema> <file> [files...]] [flags]
  4. Flags:
  5. -c, --config string config file
  6. -h, --help help for clerk
  7. -v, --version version for clerk

Example 1: Validate local files

  1. $ clerk ./testlib/data/test_schema.json ./testlib/data/test_invalid_doc.json ./testlib/data/test_valid_doc.json
  2. ./testlib/data/test_invalid_doc.json: invalid JSON, reasons: [age: Invalid type. Expected: integer, given: string]
  3. ./testlib/data/test_valid_doc.json: pass

Example 2: Validate documents from MongoDB

  1. $ clerk -c ./testlib/data/test_config.yml
  2. ObjectID("60328b85f18db7837a0d600e"): pass
  3. ObjectID("60328b8ff18db7837a0d601c"): invalid JSON, reasons: [age: Invalid type. Expected: integer, given: string]

Config

You can find the file at testlib/data/test_config.yml:

  1. clerk:
  2. schema:
  3. $id: "https://example.com/person.schema.json"
  4. $schema: "http://json-schema.org/draft-07/schema#"
  5. properties:
  6. age:
  7. minimum: 0
  8. type: integer
  9. firstName:
  10. type: string
  11. lastName:
  12. type: string
  13. title: Person
  14. type: object
  15. sourceRemotes:
  16. -
  17. args:
  18. database: test
  19. collection: people
  20. provider: mongodb
  21. uri: "mongodb://localhost:27017"
  22. targetFiles: # not implemented now
  23. - test_valid_doc.json
  24. - test_invalid_doc.json