dasel
dasel copied to clipboard
Preserve order of keys
Is your feature request related to a problem? Please describe.
I was using dasel to bump the version in a package.json file. The actual edit in the diff that I have provided below is just the version changing from 0.0.1 to 0.0.2 but since dasel rearranges the keys, that info is lost in the diff. This might be a bit of a stretch, but would it be possible to preserve the order of the keys in json and toml files? Right now, I believe it reorders the keys in alphabetical order.
Describe the solution you'd like
No reordering of the keys, the diff should just be the version line
Describe alternatives you've considered Blissful ignorance of the problem (not bad)
Additional context
diff --git a/package.json b/package.json
index b49b044..a027082 100644
--- a/package.json
+++ b/package.json
@@ -1,17 +1,17 @@
{
- "name": "marker",
- "version": "0.0.1",
+ "author": "Abin Simon",
"description": "Online tool to convert markdown to presentations",
- "main": "index.js",
- "author": "Abin Simon",
+ "devDependencies": {
+ "snowpack": "^3.1.2"
+ },
"license": "Apache-2.0",
+ "main": "index.js",
+ "name": "marker",
"scripts": {
- "start": "snowpack dev",
- "start-node": "snowpack dev --polyfill-node",
"build": "snowpack build",
- "snowpack": "snowpack"
+ "snowpack": "snowpack",
+ "start": "snowpack dev",
+ "start-node": "snowpack dev --polyfill-node"
},
- "devDependencies": {
- "snowpack": "^3.1.2"
- }
+ "version": "0.0.2"
}
This would be fantastic.
I am planning on looking into this. I may need to implement custom JSON encoders/decoders to get this working
Hey, just checking in if you have any news on this. Thanks!
Nothing yet I'm afraid - I'm pretty busy right now
Any update on this? I would love to use dasel, but comparing the changes it makes in git becomes crazy when all the keys reorder. Find myself needing to stick with find/replace for this reason. In my case it's Yaml being reordered.
The difficulty around this is that maps in go aren't strictly sorted, meaning I'll have to largely rethink the storage layer. I've had some ideas in this area but haven't had the time to test any of them out yet.
Chiming in here as I found dasel after looking for something to update a toml file. In my case I'm bumping a version in a Pipfile which gets reordered.
Would think you could use same storage mechanism and just increment a sortorder value on each key as you store them, then sort by it at each level while rebuilding the file.
The idea there is correct, but dasel unmarshals into the actual data structure, i.e. a map[string]interface{}.
I need to create a value wrapper that allows me to store things like sort order on it first.
See my draft PR here for information on where we're at with this request: https://github.com/TomWright/dasel/pull/289
I guess this can now be closed :D