Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'d like to know whether there are any JavaScript code libraries which allow wa

ID: 656898 • Letter: I

Question

I'd like to know whether there are any JavaScript code libraries which allow walking through a JSON Schema and JSON data file in conjunction such that one could grab type/schema information while walking through a JSON data file (without it being limited to whole-document validation).

Although such a tool might allow piecemeal validation, it would not need to be used for validation but would simply provide JSON Schema type information corresponding to any point in a JSON data file.

My interest in this would be as the core for the following uses for arbitrary JSON paired to a JSON schema file:

a default display of a JSON file similar to JHTML, but JSON Schema-aware (e.g., displaying not only arrays as lists, strings within a bordered area, etc., but also URLs as links, HTML within an iframe preview, etc.)
type-aware editing of a JSON file (similar to JSONEditor) or a subset/joins of JSON files
type-aware (and hierarchy-aware) default search options for arbitrary JSON (e.g., exposing a date range UI when detecting date types--for refining one's search to branches of a data file which included date types of a certain range)
enhancing JSONPath to be schema-aware (e.g., allowing for a single path expression to find all URL instances in a file)

Explanation / Answer

It seems like I met the same problem some time ago and also did not found a solution. So I've created my own tool to iterate over JSON schema and object. You may take a look at it here

It allows to write your own processors the following way:

var s = require('schemasaurus');

var it = s.newIterator({...your schema... }, function () {
return {
//matches all string fields (accroding to schema)
"[type=string]": function (schema, object, ctx) {
console.log("string field [" + ctx.path.join('.') + "] = " + object");
}
}
});

it({...your object...});

Please check github repo for more examples.

Hope that helps.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote