Created
October 2, 2019 16:59
-
-
Save glurp/f37df8aab5d58c4cd77c4a5637a38fd9 to your computer and use it in GitHub Desktop.
On json syntaxe error, pretty-print the fragment where the issue occure
This file contains hidden or 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/ruby | |
require 'json' | |
mess=File.read(ARGV.first).split(/\r?\n/).join("").gsub(/\s\s+/," ") | |
loop { | |
JSON.parse(mess) rescue break | |
exit(0) | |
} | |
loop { | |
a=mess[/({[^{]*?},?)/,1] | |
break unless a | |
JSON.parse(a.gsub(/,$/,"")) rescue puts("Error json #{$!} : #{$!.to_s.size<30 ? a : ''}") | |
mess=mess.gsub(a,'') | |
} | |
JSON.parse(mess.gsub(/,$/,"")) rescue puts("Error json #{$!}") if mess.strip.size>0 | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment