json-editor
json-editor copied to clipboard
Problem with recursive - self references
Hi,
I just checked an examples of recursive reference in the examples folder.
In the sample file examples/recursive.html, if I change the schema like this:
{
// The schema for the editor
schema: {
title: "Person",
$ref: "#/definitions/person",
definitions: {
experson:{
type: "object",
id: "experson",
properties: {
lname: {
type: "string",
title: "lastname"
}
}
},
person: {
type: "object",
id: "person",
// The object will start with only these properties
defaultProperties: [
"fname",
"lname",
"bestFriends",
"coworkers"
],
patternProperties: {
// Self-referntial schema in patternProperties
"^cousin_[0-9]+$": {
$ref: "#/definitions/person"
}
},
properties: {
fname: {
title: "first name",
type: "string"
},
lname: {
title: "last name",
type: "string"
},
bestFriends: {
title: "best friends",
type: "array",
items:{
oneOf: [
{
title: "exPerson",
$ref: "#/definitions/experson"
},
// Self-referential schema as 2nd choice in oneOf
{
title: "person",
$ref: "#/definitions/person"
}
]
}
},
coworkers: {
type: "array",
// Self-referential schema in array items
items: {
title: "Coworker",
$ref: "#/definitions/person"
}
},
// Self-referential schemas in non-default properties
mother: {
title: "mother",
$ref: "#/definitions/person"
}
}
},
year: {
type: "integer",
pattern: "^[0-9]{4}$",
minimum: 1900,
maximum: 2100
}
}
}
}
I added an additional schema called "experson" and a new property named "bestfriends" whose type is an array of "person" or "experson". Then I got an error in Developer Tools in my browser: (see attachment)
Uncaught TypeError: Converting circular structure to JSON
And the form is generated incorrectly.
Anyone has idea about this issue?
Just tried this in the live demo, indeed it does fail (direct link)
The "Uncaught TypeError: Converting circular structure to JSON" happens in the demo page because the author uses JSON.stringify for UI purposes. In this case, the author wanted to save the current schema as base64 data.
The library can handle properly formed definitions with circular references.