13 {
14 if (argc != 2) {
15 fprintf(stderr, "Usage: schemavalidator schema.json < input.json\n");
16 return EXIT_FAILURE;
17 }
18
19
21 char buffer[4096];
22
23 {
24 FILE *fp = fopen(argv[1], "r");
25 if (!fp) {
26 printf("Schema file '%s' not found\n", argv[1]);
27 return -1;
28 }
32 fprintf(stderr, "Schema file '%s' is not a valid JSON\n", argv[1]);
33 fprintf(stderr, "Error(offset %u): %s\n",
36 fclose(fp);
37 return EXIT_FAILURE;
38 }
39 fclose(fp);
40 }
41
42
44
45
50
51 fprintf(stderr, "Input is not a valid JSON\n");
52 fprintf(stderr, "Error(offset %u): %s\n",
55 }
56
57
58 if (validator.IsValid()) {
59 printf("Input JSON is valid.\n");
60 return EXIT_SUCCESS;
61 }
62 else {
63 printf("Input JSON is invalid.\n");
65 validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);
66 fprintf(stderr,
"Invalid schema: %s\n", sb.
GetString());
67 fprintf(stderr, "Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword());
69 validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);
70 fprintf(stderr,
"Invalid document: %s\n", sb.
GetString());
71
74 validator.GetError().Accept(w);
75 fprintf(stderr,
"Error report:\n%s\n", sb.
GetString());
76 return EXIT_FAILURE;
77 }
78}
File byte stream for input using fread().
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion).
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
const Ch * GetString() const
Writer with indentation and spacing.
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
GenericSchemaDocument< Value, CrtAllocator > SchemaDocument
GenericSchemaValidator< SchemaDocument, BaseReaderHandler< UTF8< char >, void >, CrtAllocator > SchemaValidator
GenericReader< UTF8< char >, UTF8< char >, CrtAllocator > Reader
GenericStringBuffer< UTF8< char >, CrtAllocator > StringBuffer
RAPIDJSON_NAMESPACE_BEGIN const RAPIDJSON_ERROR_CHARTYPE * GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
@ kParseErrorTermination
Parsing was terminated.