Command line interface #39

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

Projects

None yet

2 participants

@hickford

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

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

@garycourt
Owner

I guess I could. Or you could. :)

@hickford

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
Owner

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

@hickford

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

@kewisch kewisch added a commit to kewisch/JSV that referenced this issue Oct 24, 2012
@kewisch kewisch Issue #39 - Command line interface 7da62f3
@kewisch kewisch referenced this issue Oct 24, 2012
Closed

Cmdline app #55

@kewisch kewisch added a commit to kewisch/JSV that referenced this issue Oct 24, 2012
@kewisch kewisch Issue #39 - Command line interface b032799
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment