-1

How to stringify the system object of javascript? (cf) Event Object, DOM Object

JSON.stringify does not fully stringify the object. I wanna stringify it and load to object from the stringified string.

dashdashzako
  • 1,268
  • 15
  • 24
  • 3
    You cannot do this. JSON only supports nulls, numbers, strings, arrays and basic objects. If an object can be constructed, you can make a custom serializer/deserializer. You also cannot serialize to JSON any structure with circular references. – Amadan Oct 19 '16 at 08:02
  • 3
    Duplicate of http://stackoverflow.com/questions/11547672/how-to-stringify-event-object – abhirathore2006 Oct 19 '16 at 08:04

1 Answers1

0

JSONML is one library which can leverage the output what you're looking for.

URL: http://www.jsonml.org/

For eg,

The below DOM snippet,

<ul>
   <li style="color:red">First Item</li>
   <li title="Some hover text." style="color:green">
     Second Item
   </li>
   <li><span class="code-example-third">Third</span>Item</li>
</ul>

will be converted as,

[
    "ul",
    [
        "li",
        {
            "style": "color:red"
        },
        "First Item"
    ],
    [
        "li",
        {
            "title": "Some hover text.",
            "style": "color:green"
        },
        "Second Item"
    ],
    [
        "li",
        [
            "span",
            {
                "class": "code-example-third"
            },
            "Third"
        ],
        " Item"
    ]
]
David R
  • 14,711
  • 7
  • 54
  • 72