Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Friday February 01, 2008
04:38 AM

Bermuda - YAML and JSON Serialization

[ #35551 ]

It's dawned on me that I get YAML and JSON serialization for free now. My default may not work for your default (in fact, it probably won't), but here's what I have:

print $friend->to_xml;
print $friend->to_yaml;
print $friend->to_json;

That outputs:

<?xml version="1.0" encoding="utf-8"?>
  <dummy version="3" name="Victoria" some_val="4">
  name: Victoria
  some_val: 4
  version: 3
    attributes: {}
    name: personal_email
    attributes: {}
    name: work_email
  "elements" : [
      "value" : "",
      "name" : "personal_email",
      "attributes" : {

      "value" : "",
      "name" : "work_email",
      "attributes" : {

  "name" : "dummy",
  "attributes" : {
    "version" : 3,
    "name" : "Victoria",
    "some_val" : 4

I'll probably have to adjust the code to optionally strip out empty elements and attributes since those look strange in the YAML and JSON.

Update: no, just serializing things directly into JSON and YAML is lousy. This clearly needs work.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.