Skip to content

Conversation

@MSurfer20
Copy link
Member

@MSurfer20 MSurfer20 commented Mar 11, 2021

Currently the API response keys were sorted in random order, making
the responses unreadable. Added JSON dumps to sort the response keys.
Fixes zulip/zulip#17428

Currently the API response keys were sorted in random order, making
the responses unreadable. Added JSON dumps to sort the response keys.
versioned_url = API_VERSTRING + (url if url is not None else "")
return self.do_api_query(marshalled_request, versioned_url, method=method,
longpolling=longpolling, files=files, timeout=timeout)
return json.dumps(self.do_api_query(marshalled_request, versioned_url, method=method,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely don't want to do JSON dumps here -- a program accessing this wants the Python dictionary.

What I think we want to do here is sorting in #663 and in all the tools in examples/, so the main PR to do here would be to adjust examples/ appropriately.

Copy link
Member Author

@MSurfer20 MSurfer20 Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timabbott Can we instead change this to

return json.loads(json.dumps(self.do_api_query(marshalled_request, versioned_url, method=method,
                                 longpolling=longpolling, files=files, timeout=timeout), sort_keys=True))

since dictionaries are ordered from Python 3.7(and CPython 3.6)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timabbott Should I instead go with the modifying examples/ approach?

Copy link
Contributor

@LoopThrough-i-j LoopThrough-i-j Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will help if someone is running zulip in an env where python <= 3.6.
The only way is updating examples/.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think after thinking about this more, I'm not sure there's anything we want to do client-side -- the extra code in the examples is unlikely to be worth it.

@timabbott timabbott closed this May 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sort keys in API responses for improved readability.

4 participants