Created
March 23, 2022 09:30
-
-
Save tannie/ccf89354b70beacc5ae31a1cc7acdd2d to your computer and use it in GitHub Desktop.
Fix Facebook's unicode issues (in the downloaded archive of your data)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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