Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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

Replies are listed 'Best First'.
Re: Storable style de-serializing for JSON structures
by Corion (Patriarch) 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
Domain Nodelet?
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 browsing the Monastery: (4)
As of 2022-06-28 06:25 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (90 votes). Check out past polls.