Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6770493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:19:08+00:00 2026-05-26T15:19:08+00:00

When reading some JSON data structures, and then trying to Dump them using YAML::Tiny

  • 0

When reading some JSON data structures, and then trying to Dump them using YAML::Tiny, I sometimes get the error

YAML::Tiny does not support JSON::XS::Boolean

I understand why this is the case (in particular YAML::Tiny does not support booleans, which JSON is keen to clearly distinguish from other scalars), but is there a quick hack to turn those JSON::XS::Boolean objects into plain 0‘s and 1‘s just for quick dump-to-the-screen purposes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:19:08+00:00Added an answer on May 26, 2026 at 3:19 pm

    YAML::Tiny doesn’t support objects. Unfortunately, it doesn’t even have an option to just stringify all objects, which would handle JSON::XS::Boolean.

    You can do that fairly easily with a recursive function, though:

    use strict;
    use warnings;
    use 5.010; # for say
    
    use JSON::XS qw(decode_json);
    use Scalar::Util qw(blessed reftype);
    use YAML::Tiny qw(Dump);
    
    my $hash = decode_json('{ "foo": { "bar": true }, "baz": false }');
    
    # Stringify all objects in $hash:
    sub stringify_objects {
      for my $val (@_) {
        next unless my $ref = reftype $val;
        if (blessed $val) { $val = "$val" }
        elsif ($ref eq 'ARRAY') { stringify_objects(@$val) }
        elsif ($ref eq 'HASH')  { stringify_objects(values %$val) }
      }
    }
    
    stringify_objects($hash);
    
    say Dump $hash;
    

    This function doesn’t bother processing scalar references, because JSON won’t produce them. It also doesn’t check whether an object actually has overloaded stringification.

    Data::Rmap doesn’t work well for this because it will only visit a particular object once, no matter how many times it appears. Since the JSON::XS::Boolean objects are singletons, that means it will only find the first true and the first false. It’s possible to work around that, but it requires delving into the source code to determine how keys are generated in its seen hash:

    use Data::Rmap qw(rmap_ref);
    use Scalar::Util qw(blessed refaddr);
    
    # Stringify all objects in $hash:
    rmap_ref { if (blessed $_) { delete $_[0]->seen->{refaddr $_};
                                 $_ = "$_" } } $hash;
    

    I think the recursive function is clearer, and it’s not vulnerable to changes in Data::Rmap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read some JSON data from the Tumblr API. I'm using the
I am using jQuery to get back some JSON data from the server. I
I've been reading some tutorials on how to get started using Rails 2.0. (Time
I've created a simple TabActivity which builds tabs at runtime reading some JSON data.
I'm using JSON.Net to try and deserialize some survey responses from SurveyGizmo. Here's a
I'm mapping my request's JSON POST data into an object using Spring's @RequestBody annotation
Been reading up on php and json and am trying this piece of code
My question is: can we use dojo.xhrPost to post some Json data? More detail:
My Python program receives JSON data, and I need to get bits of information
I am reading from database with some text in Hebrew and trying to json_encode

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.