Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of JSON elements not same in Pretty and Raw view #72

Open
stedero opened this issue Aug 18, 2020 · 7 comments
Open

Order of JSON elements not same in Pretty and Raw view #72

stedero opened this issue Aug 18, 2020 · 7 comments
Labels

Comments

@stedero
Copy link

stedero commented Aug 18, 2020

The order in Pretty is wrong:
{
"product": {
"digest": "42d87a4e7abeb542a163f30e956b6db95c70a4b3ceb8200d46c6ca133ff9da50",
"priceUSD": 125,
"autoProcess": true,
"priceEUR": 105,
"mediaType": "Print",
"code": "030A16",
"cartEnabled": true,
"description": "Article 16 of the OECD Model Convention: History, Scope and Future",
"relatedItems": [
{
}, {
}
],
"isbn": "9789087223199",
"shippable": true,
"productType": "Book",
},
}

Raw:

{"product":{"code":"030A16","description":"Article 16 of the OECD Model Convention: History, Scope and Future","isbn":"9789087223199","priceEUR":105.0,"priceUSD":125.0,"productType":"Book","mediaType":"Print","relatedItems":["06DA16","06EA16"],"autoProcess":true,"cartEnabled":true,"shippable":true,"digest":"42d87a4e7abeb542a163f30e956b6db95c70a4b3ceb8200d46c6ca133ff9da50"}}

@lm2343635
Copy link
Member

Can you provide a url for this response?

@lm2343635 lm2343635 added the bug label Aug 18, 2020
@stedero
Copy link
Author

stedero commented Aug 18, 2020

Can you provide a url for this response?

I'm afraid not. This service is on our company internal network. I will see if I can find a service that is exposed outside and having the same problem.

@lm2343635
Copy link
Member

No problem, we can just put it into a github raw file to test it

@stedero
Copy link
Author

stedero commented Aug 18, 2020 via email

@lm2343635
Copy link
Member

Sorry for late reply.
JSON definition says:

An object is an unordered set of name/value pairs.
http://www.json.org/

The library SwiftyJSON to analysis json, does not keep the order too.
It's hard to keep the original order, but we can sort it again by the order of alphabet.

@stedero
Copy link
Author

stedero commented Sep 22, 2020 via email

@lm2343635
Copy link
Member

This project relies on MGFormatter to format json string, which relies on SwiftyJSON to read and analysis json.
To keep the same order, all of MGFormatter have to be rewritten.
I will try to find a library which can analysis json as the same order as the original string.
If you find any library, please told me.
Anyway, rewriting it by myself is impossible, cost a lot of time and cause unknown errors.
I will sort json keys by the order of alphabet, and update this project, hope you like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants