Skip to content

Instantly share code, notes, and snippets.

@tannie
Created March 23, 2022 09:30
Show Gist options
  • Save tannie/ccf89354b70beacc5ae31a1cc7acdd2d to your computer and use it in GitHub Desktop.
Save tannie/ccf89354b70beacc5ae31a1cc7acdd2d to your computer and use it in GitHub Desktop.
Fix Facebook's unicode issues (in the downloaded archive of your data)
#!/usr/bin/env ruby
require 'json'
file = File.open(ARGV[0])
bytes_re = /((?:\\\\)+|[^\\])(?:\\u[0-9a-f]{4})+/
content = file.read.gsub(bytes_re) do |bad_unicode|
$1 + eval(%Q{"#{bad_unicode[$1.size..-1].gsub('\u00', '\x')}"}).to_json[1...-1]
end
json = JSON.parse(content)
content = JSON.pretty_generate(json)
File.open("output.json", 'w') { |file| file.write content }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment