Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command line interface #39

Open
hickford opened this issue May 9, 2012 · 4 comments
Open

Command line interface #39

hickford opened this issue May 9, 2012 · 4 comments

Comments

@hickford
Copy link

hickford commented May 9, 2012

Hi. Do you intend to add a command line interface to this library?

(a la https://github.com/zaach/jsonlint )

@garycourt
Copy link
Owner

I guess I could. Or you could. :)

@hickford
Copy link
Author

Hi I tried.

JSV = require('jsv').JSV
fs = require('fs')

raw_object = fs.readFileSync(process.argv[2])
object = JSON.parse(raw_object)

raw_schema = fs.readFileSync(process.argv[3])
schema = JSON.parse(raw_schema)

env = JSV.createEnvironment()
report = env.validate(object, schema)

console.log(report.errors)

JSON Schemas can themselves be described using JSON Schemas. A self-describing JSON Schema for the core JSON Schema can be found at http://json-schema.org/schema for the latest version or http://json-schema.org/draft-03/schema for the draft-03 version.

But I can't get the self-describing schema to validate against itself. I get errors:

$ coffee validate.coffee schema schema
[ { uri: 'http://json-schema.org/schema#/properties/properties/additionalProperties',
    schemaUri: 'http://json-schema.org/draft-03/hyper-schema#/properties/additionalProperties',
    attribute: 'type',
    message: 'Instance is not a required type',
    details: [ 'http://json-schema.org/draft-03/hyper-schema#', 'boolean' ] },
  { uri: 'http://json-schema.org/schema#/properties/items/items',
    schemaUri: 'http://json-schema.org/draft-03/hyper-schema#/properties/items',
    attribute: 'type',
    message: 'Instance is not a required type',
    details: [ 'http://json-schema.org/draft-03/hyper-schema#', 'array' ] },
  { uri: 'http://json-schema.org/schema#/properties/extends/items',
    schemaUri: 'http://json-schema.org/draft-03/hyper-schema#/properties/items',
    attribute: 'type',
    message: 'Instance is not a required type',
    details: [ 'http://json-schema.org/draft-03/hyper-schema#', 'array' ] } ]

@garycourt
Copy link
Owner

Are you overriding the builtin schema/hyper schema by loading a new one in? It'll probably fail in that case.

@hickford
Copy link
Author

hickford commented Jun 1, 2012

https://github.com/zaach/jsonlint , a command-line tool, now uses JSV for this

kewisch added a commit to kewisch/JSV that referenced this issue Oct 24, 2012
@kewisch kewisch mentioned this issue Oct 24, 2012
kewisch added a commit to kewisch/JSV that referenced this issue Oct 24, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants