jmespath/go-jmespath

The order of an object to array conversion seems to be unstable

Closed this issue · 0 comments

I have a json alphabetically ordered as input to the Search method. When I use a query which converts an object to an array, the order gets lost. This does not seem to be the case in over implementations of the jmespath specification like the jmespath.js library. The query I am using is the following:

{labels: ['Feels Like', 'Humidity', 'Pressure', 'Temperature', 'Max Temp', 'Min Temp'], datasets: [{label: 'Weather', data: main.*}]}

The output I am getting is the following:

{
	"labels": [
		"Feels Like",
		"Humidity",
		"Pressure",
		"Temperature",
		"Max Temp",
		"Min Temp"
	],
	"datasets": [
		{
			"label": "Weather",
			"data": [
				-2.46,
				86,
				1022,
				1.44,
				3.33,
				0
			]
		}
	]
}

The numbers in the data array change randomly the order, even though the input object is always alphabetically ordered. My Golang code looks like the following:

var d2 interface{}
json.Unmarshal([]byte(tmp), &d2)

log.Printf("before: %#v", d2)
queried, err := jmespath.Search(data.Query, d2)
if err != nil {
	log.Fatal(err)
}

log.Printf("after: %#v", queried)

From the json specification lists have to stay ordered and fields in objects are unordered. So I have this problem with converting an object to an array since I need another array with labels which refers to it in the same order.

Is this an implementation issue? How can I solve this?

Best regards,

Thilo