-1

I have a jquery element as object:

var created = $('#object');

and I want to parse it to JSON with this method:

var json = JSON.stringify(created);

but its throwing

Maximum call stack size exceeded error

Is there any way that I can get this element as JSON?

Ertan Hasani
  • 797
  • 1
  • 18
  • 37

1 Answers1

0

the dom elements have a lot of child properties that references other parent properties and because of this you have a loop to serialize it. If you analyse your $('#object') on console you can view what i'm talking about. Using JSON.stringify(created, function (k, v) { return k ? "" + v : v; }); you avoid this.

  • this is not working, since its returning `[object Object]` as string – Ertan Hasani Jun 12 '18 at 07:50
  • 1
    This is suposed to work on root element only, if you "enter" on objects you have the same problem. If you need the html of the element this can be simples like element.innerHtml, but if you have to serialize as JSON you have to chose upfront the properties you want. Serialize a full Jquery object it's impossible because the circular references. – Francis Pires Jun 15 '18 at 19:43