I am fiddling around with p5 and javascript data i/o. I have an array of objects that have complex structures and functions encapsulated inside. (Like my_object.parents is another array full of the exact kind of the my_object). I am trying to implement a save as json and load from that json mechanic to my project. But when i load a json, it is recognized as an generic(?) object. So my encapsulated functions fail to work. I tried to create a a temporary object and than copy the values into it but it is a pain in the arse when we have recursive arrays. Is there an easier way to cast/parse or just solve this problem.
Asked
Active
Viewed 34 times
0
-
Please provide a [minimal, reproducible example](/help/minimal-reproducible-example). – D. Pardal Jun 03 '20 at 20:37
-
1`JSON.parse()` will get you `Object` of JSON. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse – Justinas Jun 03 '20 at 20:39
-
1There are specialized JSON formats that 'remember' the type of object they were created from (by adding additional metadata to the JSON), yes. Search for "javascript json restore original objects". – user2864740 Jun 03 '20 at 20:42
-
https://stackoverflow.com/q/14027168/2864740 (still manual though; not meta-based) – user2864740 Jun 03 '20 at 20:45
-
@user2864740 Exactly what i was looking for. Thank you Veeeery much. – Mustafa Çığ Gökpınar Jun 03 '20 at 20:45