Document View for JSON #53
Replies: 3 comments 13 replies
-
I think the most reasonable way to deal with it would be for comments to be their own type of entry inside any json object or array, and also have a top level json "container" for the entire file. That would naturally preserve the order and allow to keep any extra information. It would mean they are no longer associated with any given elements, but there could be a way to access an element with comment context around it, and then it would be on the user of that library to decide how to interpret it when manipulating the data. In json object it wouldn't be associated with any key, but could be accessible in a collection of all entries. Edit: I didn't think about comment being in the middle of a key-value pair. At that point it would also require putting an optional comment field in each a json object entry. Alternatively, comments could be be considered more as separate things in each json object and array, with information about which elements are before and after it (possibly including information whether it's on the same line or a different line?). Moving, removing and adding elements would need an option to specify how to deal with comments around it. But at least for my use case, I think the most natural way to represent it would be for json objects to just expose a collection of some sort of "json object components" which could be: |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Starting to implement the Document view in mainline. How should we relate the semantic objects to the structural ones? What level of caching or defensive copying should occur? Does, say, a structural change in the document affect any derived semantic objects, and vise versa? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When I say "Document" I don't mean
org.w3c.dom.Document
, but it's on my mind. Preserving ordering and comments are a pillar of this library and honestly some of the edge-case behavior is still unacceptable.Currently, comments are attributed to a node in the node-list (usually a key-value pair). But what happens in this case?
The best thing we could do after a roundtrip right now is this
And I'm really not sure we're even doing that. Worse, what do we do here?
So every object needs to also carry around a "top-level comment" field?
What I want to do, and this is going to be a big project, is to create a structural view of the file. That is, an object is a sub-file and contains individual nodes for keys, objects, multiline comments, end-of-line comments, etc, and can be used to more or less recreate the original file, without moving or merging comments. We will fix indentation and any errors we find along the way, and in some ways regularize the file. This is important for jankson's usefulness as a preprocessor. But this would unhook the comments from the key-value pairs and give us a foothold up to handling all the edge cases.
Does such an object continue to support random access and structural modifications? Do we replace the implementation for JsonObject, or hold these two views into the file as distinct - one document view and one semantic view, and let the user pick which one they want to work with for any given task?
This is a hard design problem, and I'm looking for input on how we could get it done cleanly and clearly.
Beta Was this translation helpful? Give feedback.
All reactions