Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Storable style de-serializing for JSON structures

by Anonymous Monk
on Oct 11, 2009 at 07:13 UTC ( #800512=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

Wisdom I seek ..

I am receiving JSON serialized objects for some perl classes. I can easily de-serialize the JSON structure back into perl data structure - hash/array using standard JSON modules and possibly into a blessed reference.

However, when the serialized class represents objects and sub-objects, I have no way to automatically create blessed reference for sub-objects.

Storable module can easily de-serialize and create blessed references for sub-objects automatically. Is there a way to do the same for JSON?

Gracias Dece

Comment on Storable style de-serializing for JSON structures
Re: Storable style de-serializing for JSON structures
by Corion (Pope) on Oct 11, 2009 at 08:32 UTC

    As far as I understand the idea of JSON, it's supposed to be cross-language, and hence doesn't really have a concept of "classes". At least JSON does not want to serialize blessed objects by default, and I guess that there is no way to (de)serialize whole class trees. Maybe you can store the class name as a separate field for each object and upon deserialization rebless all elements?

      Thanks for reply. I agree with your suggestion
Re: Storable style de-serializing for JSON structures
by Joost (Canon) on Oct 11, 2009 at 22:47 UTC
    JSON doesn't support anything but "dumb" data structures. No class instances or anything like that.

    Storable and Data::Dumper and others just produce string data, and can serialize perl objects. If all you care about is something that's technically JSON and you only pass it to other perl code, you can put the serialized string into a JSON attribute and retrieve it on the other side.

    The real question would then be: why use JSON at all?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://800512]
Approved by wfsp
Front-paged by wfsp
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (16)
As of 2014-07-28 13:58 GMT
Find Nodes?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:

    Results (200 votes), past polls