Skip to content

Instantly share code, notes, and snippets.

@russolsen
Created July 3, 2014 12:02
Show Gist options
  • Save russolsen/56a0750da28216e18042 to your computer and use it in GitHub Desktop.
Save russolsen/56a0750da28216e18042 to your computer and use it in GitHub Desktop.
require 'oj'
require 'stringio'
require 'json'
class Handler
def hash_start
{}
end
def hash_set(h,k,v)
h.store(k,v)
end
def array_start
[]
end
def array_append(a,v)
a << v
end
def add_value(v)
p v
end
def error(message, line, column)
raise Exception.new(message, line, column)
end
end
handler = Handler.new
read_io, write_io = IO.pipe
if fork
write_io.close
Oj.sc_parse(handler, read_io)
read_io.close
Process.wait
else
json = {"glossary"=>{"GlossDiv"=>{"GlossList"=>{"GlossEntry"=>{"Abbrev"=>"ISO 8879:1986", "Acronym"=>"SGML", "GlossDef"=>{"GlossSeeAlso"=>["GML", "XML"], "para"=>"A meta-markup language, used to create markup languages such as DocBook."}, "GlossSee"=>"markup", "GlossTerm"=>"Standard Generalized Markup Language", "ID"=>"SGML", "SortAs"=>"SGML"}}, "title"=>"S"}, "title"=>"example glossary"}}
{"glossary"=>{"GlossDiv"=>{"GlossList"=>{"GlossEntry"=>{"Abbrev"=>"ISO 8879:1986", "Acronym"=>"SGML", "GlossDef"=>{"GlossSeeAlso"=>["GML", "XML"], "para"=>"A meta-markup language, used to create markup languages such as DocBook."}, "GlossSee"=>"markup", "GlossTerm"=>"Standard Generalized Markup Language", "ID"=>"SGML", "SortAs"=>"SGML"}}, "title"=>"S"}, "title"=>"example glossary"}}
{"glossary"=>{"GlossDiv"=>{"GlossList"=>{"GlossEntry"=>{"Abbrev"=>"ISO 8879:1986", "Acronym"=>"SGML", "GlossDef"=>{"GlossSeeAlso"=>["GML", "XML"], "para"=>"A meta-markup language, used to create markup languages such as DocBook."}, "GlossSee"=>"markup", "GlossTerm"=>"Standard Generalized Markup Language", "ID"=>"SGML", "SortAs"=>"SGML"}}, "title"=>"S"}, "title"=>"example glossary"}}.to_json
read_io.close
write_io.write json
write_io.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment