ActiveSupport::JSON::Encoding SystemStackError: stack level too deep


Is there anyone here who knows how ActiveSupport::JSON::Encoding works? I have been trying to check issue, but I am getting confused in all the times the encoder goes through the values. I think that it is too convoluted to what it intends to do, with the use_options flags and the encode_json and as_json methods in the core classes. Is someone here familiarized with that code to give me some help in fixing this issue? I have created a test that breaks with a SystemStackError:

def test_exception_raised_when_encoding_circular_reference_in_hash_inside_object

a = {}

b =, nil)

a[“a”] = b

assert_raise(ActiveSupport::JSON::Encoding::CircularReferenceError) { ActiveSupport::JSON.encode(a) }


Best regards,

I’m working on a PR in the same area (AS::JSON::Encoding). I allocated some time to work on this on Tuesday at our local ruby hack night. If your still need help by then we can probably look into this together. Chat on IRC?

That would be great. At what time is the hack? I’m at GMT -4 (Chile)