Skip to content

Instantly share code, notes, and snippets.

@themiurgo
Created September 25, 2012 13:36
Show Gist options
  • Save themiurgo/3781917 to your computer and use it in GitHub Desktop.
Save themiurgo/3781917 to your computer and use it in GitHub Desktop.
Convert a one-line stream of JSON objects into a newline separated (multiline) stream
#/bin/bash
# Fix all the files and puts them in a 'fixed' subdirectory
mkdir fixed
for f in *.gz; do gunzip -c $f | ruby jsonsm.rb | gzip -c > fixed/$f; done
require 'yajl'
Yajl::Parser.parse(STDIN) do |event|
print Yajl::Encoder.encode(event)
print "\n"
end
require 'open-uri'
require 'zlib'
require 'yajl'
#gz = open('http://data.githubarchive.org/2012-03-11-12.json.gz')
js = Zlib::GzipReader.new(STDIN).read
Yajl::Parser.parse(js) do |event|
print Yajl::Encoder.encode(event)
print "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment