Closed brianreinhold closed 1 month ago
Set the sort_keys
setting to True
. This will cause the "tags" (I prefer to call them "keys") to be sorted alphabetically as you desire.
But I think you have a bigger problem here; the order of the keys of a JSON object should not matter, because most programming languages represent it as an unordered map. If you have an internal process that breaks if the keys of a JSON object are not in a certain order, the process is at fault, not JsonTools.
I want the order of the keys to be those that I have ordered. I do NOT want them alphabetized.
The HL7 FHIR standard originally wanted the order of the keys to be as defined in the standard. They originally had that requirement for both JSON and xml, but it was soon realized that many JSON libraries could not handle that and would not do that. However, since I am writing the JSON without a library I can satisfy the order requirement in JSON. The requirement remains for xml.
I want the order of the keys to be those that I have ordered. I do NOT want them alphabetized.
@brianreinhold
My mistake, I guess I was a bit confused by your examples. In that case, sort_keys
should be set to False
. Since this plugin is implmented in C#, this will cause key order to be preserved when reformatting.
By the way, you may want to upgrade to the latest version; given that sort_keys
appears to be True
by default it would seem that you are using an older version.
The HL7 FHIR standard originally wanted the order of the keys to be as defined in the standard.
Interesting, I didn't know that.
Okay, I just installed it into NPP from the plugin manager. I will check for an update. Low and behold there was one!!
When I do a 'pretty print' of a compressed JSON string the structure is changed. It looks as if the tags are alphabetized. That behavior causes problems because in a certain standard the order of the tags is specified, and though the compressed form is correct, the pretty print form is wrong and illegal.
For example here is what I should get:
But here is what I actually get:
The first form is legal for the standard, the second one is not. Is there a way to get the pretty print to format exactly what is given?