Skip to content

Instantly share code, notes, and snippets.

@mkubdev
Created October 4, 2023 10:07
Show Gist options
  • Select an option

  • Save mkubdev/bd1c3c66fb1af0b69f19b602b0ce3899 to your computer and use it in GitHub Desktop.

Select an option

Save mkubdev/bd1c3c66fb1af0b69f19b602b0ce3899 to your computer and use it in GitHub Desktop.
Fix json of an exported mongo collection
import re
# Read the incorrect JSON file
with open('jobs.json', 'r') as file:
data = file.read()
# Add commas between documents
fixed_data = re.sub(r'}\s*{', '},\n{', data)
# Write the fixed JSON to a new file
with open('fixed_file.json', 'w') as file:
file.write(fixed_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment