Skip to content

Preserve JSON Key Order #23

@homestar9

Description

@homestar9

Summary

I'm not sure if this is possible, but being able to preserve the JSON key order to exactly match the source .json files would make a huge improvement to legibility, consistency, and easier to follow documentation.

Detailed Description

Currently, when you create a .json document which will be exported by cbswagger, the resulting JSON file struct key order appears to be random.

For example, in this schema json file example:

{
	"type": "object",
	"properties": {
		"address": {
			"type": "string"
		},
		"city": {
			"type": "integer"
		},
		"state": {
			"type": "integer"
		},
		"zip": {
			"type": "integer"
		}
       }
}

When processed by cbswagger, results in the final JSON looking like this:

{
	"type": "object",
	"properties": {
		"zip": {
			"type": "integer"
		},
		"city": {
			"type": "integer"
		},
		"address": {
			"type": "string"
		},
		"state": {
			"type": "integer"
		}
       }
}

Possible Implementation Ideas

I know ColdFusion has the ability to preserve struct order by using a Java LinkedHashMap, which works a lot like structs. Perhaps the JSON struct conversion could be done using a Java-based JSON parser which uses hash maps, so the resulting order is preserved in the final output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions