Canop / JSON.prune

A pruning version of JSON.stringify, allowing for example to stringify window or any big or recursive object
MIT License
163 stars 27 forks source link

functions #5

Closed ghost closed 8 years ago

ghost commented 8 years ago

For example, if you visit this page:

http://youtube.com/watch?v=qwspCgEUj64

Request:

yt.player.Application

Response:

Object { create: f9.create(), createWebComponent: f9.B() }

However pruned request:

JSON.prune(yt.player.Application)

Gives empty response:

"{}"
ghost commented 8 years ago

I found a workaround. Request:

yt.player.Application.toSource()

Response:

"({create:(function (a,b){try{var c=f9.C(a);if(f9.j[c]){try{f9.j[c].dispose()}catch(e){Ki(e)}f9.j[c]=null}var d=new f9(a,b);Lb(d,function(){f9.j[c]=null});
return f9.j[c]=d}catch(e){throw Ki(e),e.stack;}}), createWebComponent:(function (a,b){cv("pwc");var c=window.document.querySelector(a);window.document.registerElement(a,{});var d=c.querySelector("template"),c=c.createShadowRoot(),d=window.document.importNode(d.content,!0);c.appendChild(d);c=c.getElementById(b);d=v("ytplayer.config");c=f9.create(c,d);d.loaded=!0;return c})})"
Canop commented 8 years ago

@svnpenn Not serializing functions is the normal behavior (it's also what's done in JSON.stringify). If you want to serialize functions you may use this option of JSON.prune: https://github.com/Canop/JSON.prune#example-4-function-serialization

If you think I misunderstood the issue, please come and discuss it on Miaou: https://dystroy.org/miaou/8

ghost commented 8 years ago

@Canop ok your suggestion does work, thank you. However it should be noted that this script does not work:

http://stackoverflow.com/questions/13861254/json-stringify-deep-objects#14145840

this one does:

http://github.com/Canop/JSON.prune/blob/master/JSON.prune.js