Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nesting error when trying to parse JSONfile

Tags:

json

ruby

reddit

I'm trying to parse the JSON file of a Reddit thread with all it's comments. But when I try to parse the JSON I get a "in `parse': nesting of 20 is too deep " error.

Below is the code i use:

#require 'net/http'
#require 'rubygems'
#require 'json'

@response = Net::HTTP.get(URI.parse("http://www.reddit.com/r/AskReddit/comments/sjm1z/what_is_your_most_useless_talent/.json"))
result = JSON.parse(@response)

Is there anyway I can get around this?

It is not essential for me to have all the smaller subthreads parsed. Is there a way to set the nesting depth limit?

like image 415
bolshevik Avatar asked Dec 27 '22 02:12

bolshevik


1 Answers

Try setting the max_nesting value:

result = JSON.parse(@response, :max_nesting => 100)
like image 129
Codebeef Avatar answered Jan 07 '23 01:01

Codebeef