Skip to content

fix downloaded notebooks saved as invalid JSON - #201

Closed
DevDesai444 wants to merge 2 commits into
googlecolab:mainfrom
DevDesai444:fix/download-json-format
Closed

DevDesai444 wants to merge 2 commits into
googlecolab:mainfrom
DevDesai444:fix/download-json-format

Conversation

@DevDesai444

Copy link
Copy Markdown

Summary

  • Fixes Downloaded notebooks are saved as invalid JSON #190: colab download saves notebooks with invalid Python repr instead of valid JSON
  • When the Contents API returns format: "json", the content is a parsed dict — str() produces single-quoted keys which is not valid JSON
  • Added an explicit elif for format == "json" that uses json.dumps to serialize properly

Test plan

  • Added test_download_json_format_writes_valid_json to tests/test_contents.py
  • Verifies downloaded file round-trips through json.loads and matches original content
  • All 6 contents tests pass
  • Lint clean

The Contents API returns notebooks with format=json as a parsed dict.
Using str() on this dict produces Python repr with single-quoted keys,
which is not valid JSON. Downloaded notebooks could not be reopened.

Use json.dumps() for the json format case so the output is valid JSON.

Fixes googlecolab#190.
Adds test_download_json_format_writes_valid_json to confirm that
notebooks returned with format=json round-trip through json.loads
and match the original content dict.
@google-cla

google-cla Bot commented Oct 30, 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.

@sethtroisi

Copy link
Copy Markdown
Collaborator

This looks great! If you sign the CLA I'll merge it.

@sethtroisi

Copy link
Copy Markdown
Collaborator

Still waiting on the you to sign the CLA

@sethtroisi

Copy link
Copy Markdown
Collaborator

#232 addresses the problem

@sethtroisi sethtroisi closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Downloaded notebooks are saved as invalid JSON

2 participants