Skip to content

Add helper to update JSON files safely#2

Open
howbootcamps wants to merge 1 commit intomainfrom
codex/implement-update_json_file-function
Open

Add helper to update JSON files safely#2
howbootcamps wants to merge 1 commit intomainfrom
codex/implement-update_json_file-function

Conversation

@howbootcamps
Copy link
Owner

Summary

  • add a reusable update_json_file helper to merge dictionaries into JSON files
  • ensure automatic file creation and error handling for missing files, permissions, or invalid JSON

Testing

  • python -m compileall update_json.py

https://chatgpt.com/codex/tasks/task_e_68de63a163b8832693cc779de228b41e

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Comment on lines +48 to +51
if file_exists:
for key, value in new_data.items():
if key in existing_data:
existing_data[key] = value

Choose a reason for hiding this comment

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

P1 Badge Overwrite nested JSON objects instead of merging

When the target file exists, the loop replaces an entire value whenever the top-level key is present. If that value is itself a dictionary, providing a partial update will clobber unspecified nested keys. For example, an existing document { "settings": { "theme": "dark", "lang": "en" } } updated with new_data={"settings": {"lang": "fr"}} results in {"settings": {"lang": "fr"}}, losing theme. This contradicts the docstring’s promise to preserve the original structure and can silently drop data. A recursive merge is needed to update only the provided nested keys.

Useful? React with 👍 / 👎.

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.

1 participant