Closed hyiltiz closed 4 years ago
Hörmet Yiltiz wrote:
I tried
treeline a.json
but none of the import formats seem sensible to use for a JSON file. I can imagine converting the JSON to XML first, but it might make more sense to provide native support to JSON? The website mentions JSON so I thought importing was also supported.TreeLine files use a JSON format, with options for automatically compressing or encrypting the files.
That statement means that TreeLine uses JSON as its native storage format. Open a TreeLine file in a text editor and you'll see it.
But TreeLine doesn't offer a generic JSON import. The problem is that JSON does not have a particular defined structure. Consistently converting it into a tree (or even a list of nodes) is not possible in the general case. This is different from XML, which has a more defined nested structure.
-Doug
Could you give a counter-example? I think most of the cases can be dealt with simply adding a root node on top if it is just a plain list.
To make a counter-example clear, let me start with the very limited case that would work. A JSON file that consists of a top-level array containing nothing but objects (key/value pairs). Each object would become a node with the keys as field names and the values as the field values. It would create a flat tree (no parent/child info), but that would be fine.
But what if one of the values is an array? If the array contains objects, it could be used to define a tree structure, with the object containing an array of children. A minor issue is that the key for the array would be discarded. A more significant issue is what to do with an array containing text or number values. Even worse would be an array with a mixture of types.
Basically, it's not practical to import a generic JSON file into TreeLine.
-Doug
Did you mean something like this? Note that replacing the top level {
with [
produces a faulty file that doesn't parse as JSON.
{"a": "A",
"b": "B",
"c": {
"text": "Premature optimization!",
"number": 3.14,
"someField": "this array has Objects whose values have mixed types."
}
}
Firefox parses the above JSON
as a tree-like structure.
Of course just replacing the top level { with ] doesn't work. Arrays don't directly contain key/value pairs. Please do some research on valid JSON array syntax.
And please read what I said carefully:
To make a counter-example clear, let me start with the very limited case that would work. A JSON file that consists of a top-level array containing nothing but objects (key/value pairs). Each object would become a node with the keys as field names and the values as the field values. It would create a flat tree (no parent/child info), but that would be fine.
I said that a file with only objects would work. But most JSON files also contain arrays. Including them would break the structure, especially if they contain mixed types.
-Doug
I tried
treeline a.json
but none of the import formats seem sensible to use for a JSON file. I can imagine converting the JSON to XML first, but it might make more sense to provide native support to JSON? The website mentions JSON so I thought importing was also supported.