I am trying to utilize https://github.com/json-editor/json-editor. I have read all documentation and examples multiple times and I cannot get the editor to respect my starting values (startVal). The editor is created using my schema, but the editor is not initialized with the starting object I am providing. Here is my code:
$.get("/AppAdmin/GetWorkflowEditSchema", {}, function (schemaResponse) {
if (schemaResponse) {
var editSchema = JSON.parse(schemaResponse);
$.get("/AppAdmin/GetWorkflow?workflowName=" + workflowToEdit, {}, function (workflowResponse) {
if (workflowResponse)
{
var workflow = JSON.parse(workflowResponse);
const holder = document.getElementById("workflowEditorHolder");
var options = {
"schema": editSchema,
"startVal": workflow,
"theme": "bootstrap4"
};
jsonEditor = new JSONEditor(holder, options);
}
else {
toastr.error("The workflow could not be loaded to edit.");
}
});
}
else {
toastr.error("Reading edit schema failed.");
}
Both server responses are the correct JSON strings. When I copy and paste my schema and starting object into the json-editor interactive playground at https://pmk65.github.io/jedemov2/dist/demo.html, the editor is created with the correct starting values. So I suspect something is wrong with my objects. I am very unfamiliar with JSON so that would not be surprising.
Here is my schema:
And the object I am trying to initialize the editor with:
What am I doing wrong? Thank you for any help.
I got this working by using setValue() after creation instead of passing the initializing object:
var options = {
"schema": editSchema,
// "startVal": workflow,
"theme": "bootstrap4"
};
jsonEditor = new JSONEditor(holder, options);
jsonEditor.setValue(workflow);