diff --git a/source/dub/internal/vibecompat/data/json.d b/source/dub/internal/vibecompat/data/json.d index 852497b..e652bdf 100644 --- a/source/dub/internal/vibecompat/data/json.d +++ b/source/dub/internal/vibecompat/data/json.d @@ -1782,7 +1782,7 @@ static if (pretty) { import std.algorithm.searching : canFind; - enum keyOrder = [//determines the sorting order of the json + string[] keyOrder = [//determines the sorting order of the json "name", "description", "homepage", @@ -1820,6 +1820,10 @@ "lflags" ]; + foreach (string key, ref const Json val; json) { + if (!keyOrder.canFind(key)) keyOrder ~= key; + } + foreach( key; keyOrder ){ if( json[key].type == Json.Type.undefined ) continue; if( !first ) dst.put(','); @@ -1831,17 +1835,6 @@ dst.put(`": `); writeJsonString!(R, pretty)(dst, json[key], level+1); } - foreach (string key, ref const Json val; json) {//add remaining elements to the json if they weren't found in `keyOrder` - if( keyOrder.canFind(key) || val.type == Json.Type.undefined ) continue; - if( !first ) dst.put(','); - first = false; - dst.put('\n'); - foreach (tab; 0 .. level+1) dst.put('\t'); - dst.put('\"'); - jsonEscape(dst, key); - dst.put(`": `); - writeJsonString!(R, pretty)(dst, val, level+1); - } if (json.length > 0) { dst.put('\n'); foreach (tab; 0 .. level) dst.put('\t');