Skip to content

feat: request compact JSON responses by default - #2789

Open
pawciobiel wants to merge 1 commit into
googleapis:mainfrom
pawciobiel:feat/compact-json-by-default
Open

feat: request compact JSON responses by default#2789
pawciobiel wants to merge 1 commit into
googleapis:mainfrom
pawciobiel:feat/compact-json-by-default

Conversation

@pawciobiel

@pawciobiel pawciobiel commented Aug 14, 2026

Copy link
Copy Markdown

Google APIs default prettyPrint to true, so every JSON response carries indentation and line breaks that the client throws away while parsing. JsonModel now sends prettyPrint=false, mirroring the existing alt_param mechanism.

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #2788 馃

Google APIs default prettyPrint to true, so every JSON response carries
indentation and line breaks that the client throws away while parsing.
JsonModel now sends prettyPrint=false, mirroring the existing alt_param
mechanism.

Fixes googleapis#2788
@pawciobiel
pawciobiel requested a review from a team as a code owner August 14, 2026 14:04
@product-auto-label product-auto-label Bot added the size: s Pull request size is small. label Aug 14, 2026
@google-cla

google-cla Bot commented Aug 14, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request configures the client library to request compact JSON responses by default by appending prettyPrint=false to API requests, which reduces network transfer and parsing overhead. It also updates the documentation and tests to reflect this change. The feedback highlights a potential issue where mutating the params dictionary in _build_query can cause side effects for callers, suggesting that a local copy of the dictionary should be created instead.

Comment thread googleapiclient/model.py
Comment on lines 196 to 197
if self.alt_param is not None:
params.update({"alt": self.alt_param})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Mutating the params dictionary passed as an argument to _build_query can lead to unexpected side effects for the caller, especially if the dictionary is reused (e.g., in retries, batching, or by the client application). It is safer to create a local copy of the dictionary using dict(params) before modifying it.

Suggested change
if self.alt_param is not None:
params.update({"alt": self.alt_param})
params = dict(params)
if self.alt_param is not None:
params.update({"alt": self.alt_param})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disable prettyPrint by default for Google Sheets API responses

1 participant