processing large JSON without root element (Ruby) -
i new ruby, question might vary basic.
i looking ruby library help me parse big json file (of order of 100 mbs)
the peculiarity of json file is, created set of processes, , has no root element. imagine file looks this
//this element 1 { "name":"person 1", "dresses":[{"type":"pants","color":"green"},{"type":"shirt","color":"green"},{"type":"t-shirt","color":"green"}], "age":"34" } //this element 2 { "name":"person 2", "dresses":[{"type":"pants","color":"blue"},{"type":"shirt","color":"red"}], "age":"33" }
since there lot of such elements(around 3m), need find way can elements @ time,or treat input stream if possible, , write each of elements text file after processing based on values,
a guy of age 34 have 3 clothes, including pair of greenish pants a guy of age 33 has 2 clothes, , no t-shirtbasically, parsing xml using sax parser, but without root element. can please suggest ruby library work ?
if strings , poping few @ time, can utilize json.parse.
for example:
a = '{ "name":"person 1", "dresses":[{"type":"pants","color":"green"},{"type":"shirt","color":"green"},{"type":"t-shirt","color":"green"}], "age":"34" }' b = json.parse(a) b['name'] => 'person 1'
or if prefer symbols(i do!)
b = json.parse(a).deep_symbolize_keys! b[:name] => 'person 1'
if want sax machine, experimental gem: https://github.com/brianmario/json-machine
ruby-on-rails ruby json bash streaming
No comments:
Post a Comment