wk8 / go-ordered-map

Optimal implementation of ordered maps for Golang - ie maps that remember the order in which keys were inserted.
Apache License 2.0
523 stars 40 forks source link

Nested Maps #35

Closed Jack-Drake closed 1 year ago

Jack-Drake commented 1 year ago

Dear wk8,

Thank you for this amazing project, very useful. I am having an issue with JSON Unmarshalling a json string. It seems to not be adding the json as is rather it is still randomizing it.

Anything would help.

wk8 commented 1 year ago

Happy to have a look if you provide a test case :)

Jack-Drake commented 1 year ago

lol I do not have a test case except a couple screenshots image image

Jack-Drake commented 1 year ago

and this screenshot of the struct image

wk8 commented 1 year ago

See https://github.com/wk8/go-ordered-map/issues/33

Jack-Drake commented 1 year ago

I am going to be honest I do not understand. The #33. Is the idea to make a struct for each value? such as seen below? image

wk8 commented 1 year ago

I don't see the connection between your ProductModel struct and the example JSON you gave.

But regardless, the gist is that if you unmarshall to an OrderedMap[string, any], only the first level of your JSON object is going to be ordered. Any map contained in there are going to be regular, unordered map.

Jack-Drake commented 1 year ago

so what is the procedure to make sure for example that everything underneath it remains Ordered. Do i have to do the same as this picture? (https://user-images.githubusercontent.com/44513448/264916670-37af21c2-4b7b-4ccc-bea5-fc6a6ddc4cc4.png)

wk8 commented 1 year ago

I'm sorry, please provide an actual code snippet and an actual JSON input. Can't help you otherwise.

Jack-Drake commented 1 year ago

image Above is the json being used image Above is the struct that should be decoding the json. This is also the one I would like to have be in order image Above is the code I am using to parse it

wk8 commented 1 year ago

I'm not going to re-type images into text. If you're not willing to do that yourself then sorry I can't help you.