Open shamilnabiyev opened 4 years ago
If there is a dot
in the field name, it can be filtered out:
Input:
{
"obj": {
"a": true,
"d.": {
"id": 1
}
}
}
Flattened output:
{
"obj.a": true,
"obj.d..id": 1
}
Extract field name(s):
// split the string
"obj.d..id".split(".")
// returns: [ "obj", "d", "", "id" ]
// split and filter the string
"obj.d..id".split(".").filter(item => item !== "")
// returns: [ "obj", "d", "id" ]
schema.properties
{
"id": {"type": "integer"},
"str": {"type": "string"},
"arr": {
"type": "array",
"items": [
{"type": "integer"},
{"type": "string"},
{"type": "boolean"},
{"type": "number"},
{
"type": "object",
"properties": {
"empty": {},
"name": {"type": "string"},
"id": {"type": "string"},
"isStudent": {"type": "boolean"}
}
}
]
}
}
Flattened:
{
"id.type": "integer",
"str.type": "string",
"arr.type": "array",
"arr.items[0].type": "integer",
"arr.items[1].type": "string",
"arr.items[2].type": "boolean",
"arr.items[3].type": "number",
"arr.items[4].type": "object",
"arr.items[4].properties.empty": {},
"arr.items[4].properties.name.type": "string",
"arr.items[4].properties.id.type": "string",
"arr.items[4].properties.isStudent.type": "boolean"
}
Allowed property name characters: a-z A-Z 0-9 _
Use the flattening approach to replace the recursive iteration through the JSON-Docs. The flattened JSON will help to add all child cells of the DiagramRoot at the same time and thus to avoid the
z-index
problem.See the example below:
Input:
Flattened output:
Links:
http://fiddle.jshell.net/blowsie/S2hsS/show/light/ https://www.npmjs.com/package/flat https://stackoverflow.com/questions/19098797/fastest-way-to-flatten-un-flatten-nested-json-objects