From: Trans Date: 2007-11-24T12:36:41+09:00 Subject: Re: Parsing nested JSON data On Nov 23, 7:30 pm, Marko Anastasov wrote: > From a web API, I receive a JSON stream such as: > > [{"u":"http://...html","d":"some title","t":["ruby"]}, > {"u":"http://....org/","d":"another title","t": > ["ruby","json","library"]},...] > > Now, among the rest, I also want to access those "ruby", "json" and > "library" strings. > With the following code: > > @structs = JSON.parse(@json_stream) > > for i in 0...@structs.length > @struct_obj = @structs.fetch(i) > @struct_obj.each { |key, value| > if key == "t" > # get the value that 't' points to > end > } > end > > I get them all appended to each other without any whitespace, ie > "rubyjsonlibrary". > > How could I access them individually? 7stud probably covered your question, so if you don't mind I'd like to hijack this thread and ask a more general question about JSON parsing... Is it possible that JSON could be built into Ruby? The syntax is so close to Ruby's as of 1.9, that it seems a small step and rather a shame not to just go ahead and make it compatible. Off hand it seems that only quoted keys are missing. T.