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

Add JSON schema output format support #46

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion js/DataGridRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,39 @@ var DataGridRenderer = {
return outputText;
},


//---------------------------------------
// JSON Schema
//---------------------------------------


jsonSchema: function (dataGrid, headerNames, headerTypes, indent, newLine) {
//inits...
var commentLine = "//";
var commentLineEnd = "";
var outputSchema = {
"$schema": "http://json-schema.org/draft-04/schema#"
};
var numRows = dataGrid.length;
var numColumns = headerNames.length;

var baseType = numRows > 1 ? ["array", "items"] : ["object", "properties"];
outputSchema["type"] = baseType[0];


var tempOutput = {};
//begin render loop
headerNames.map(function (header, index) {
tempOutput[header] = {
"type": headerTypes[index]
};
});

outputSchema[baseType[1]] = tempOutput;
var outputText = JSON.stringify(outputSchema, null, indent);
return outputText;
},

//---------------------------------------
// JSON Array of Columns
//---------------------------------------
Expand Down Expand Up @@ -535,4 +568,4 @@ var DataGridRenderer = {

},

}
}
1 change: 1 addition & 0 deletions js/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function DataConverter(nodeId) {
{"text":"JSON - Column Arrays", "id":"jsonArrayCols", "notes":""},
{"text":"JSON - Row Arrays", "id":"jsonArrayRows", "notes":""},
{"text":"JSON - Dictionary", "id":"jsonDict", "notes":""},
{"text":"JSON Schema", "id":"jsonSchema", "notes":""},
{"text":"MySQL", "id":"mysql", "notes":""},
{"text":"PHP", "id":"php", "notes":""},
{"text":"Python - Dict", "id":"python", "notes":""},
Expand Down