Config...::Json(3pm)

🌸 Config::Model::Backend::Json 🌸

okay bestie, welcome to the manual page for Config::Model::Backend::Json β€” which shows up in the header as Config...::Json(3pm) because the terminal is being dramatic and truncating our gorgeous long name πŸ’…

✨ NAME ✨

Config::Model::Backend::Json β€” read and write config as a JSON data structure 🫢

πŸ’– VERSION πŸ’–

version 2.166 β€” yeah she's got a version number, she's a whole grown-up module ✨

πŸŽ€ SYNOPSIS πŸŽ€

okay so first you set up your whole config tree situation:

use Config::Model ;
use Data::Dumper ;

# define configuration tree object
my $model = Config::Model->new ;
$model ->create_config_class (
   name => "MyClass",
   element => [
       [qw/foo bar/] => {
           type => 'leaf',
           value_type => 'string'
       },
       baz => {
           type => 'hash',
           index_type => 'string' ,
           cargo => {
               type => 'leaf',
               value_type => 'string',
           },
       },
   ],
 rw_config  => {
   backend => 'Json' ,
   config_dir => '/tmp',
   file  => 'foo.json',
   auto_create => 1,
 }
) ;

my $inst = $model->instance(root_class_name => 'MyClass' );

my $root = $inst->config_root ;

my $steps = 'foo=yada bar="bla bla" baz:en=hello
            baz:fr=bonjour baz:hr="dobar dan"';
$root->load( steps => $steps ) ;
$inst->write_back ;

and like… now, "/tmp/foo.yml" contains:

{
  "bar" : "bla bla",
  "foo" : "yada",
  "baz" : {
     "hr" : "dobar dan",
     "en" : "hello",
     "fr" : "bonjour"
  }
}

LOOK AT HER GO πŸ”₯ that's the whole pipeline and it ate, no cap.

🌈 DESCRIPTION 🌈

So Config::Model uses this module directly to read or write the content of a configuration tree that's written with Json syntax inside a Config::Model configuration tree. That's the whole job, and she does it flawlessly 🧚

ngl there's a lil quirk you need to know: undefined values get skipped for list element. Like, if a list element contains ('a',undef,'b'), the data structure only contains 'a','b'. undef just doesn't make the cut, sorry bestie πŸ™ˆ

And heads up β€” you must install the JSON module to use this backend. no JSON module, no vibes, that's just the deal πŸ’€


πŸ‘‘ CONSTRUCTOR πŸ‘‘

πŸ¦‹ new πŸ¦‹

Parameters: ( node => $node_obj, name => 'Json' )

Inherited from Config::Model::Backend::Any. The constructor gets called by Config::Model::BackendMgr β€” you don't have to summon it yourself, she comes when she's called ✨

πŸ¦‹ read πŸ¦‹

Of all the parameters handed to this read call-back, only file_path is used. That parameter must be a Path::Tiny.

When a file is read, read returns 1. icon behavior, honestly 🫢

πŸ¦‹ write πŸ¦‹

Of all the parameters handed to this write call-back, only file_path is used. That parameter must be a Path::Tiny object.

write returns 1. consistent queen πŸ’…

⭐ AUTHOR ⭐

Dominique Dumont, (ddumont at cpan dot org)

πŸ“ SEE ALSO πŸ“

Config::Model, Config::Model::BackendMgr, Config::Model::Backend::Any,

⭐ AUTHOR ⭐

Dominique Dumont

(yes bestie, AUTHOR shows up twice, I don't make the rules, I just report them πŸ’œ)

This software is Copyright (c) 2005-2022 by Dominique Dumont.

This is free software, licensed under:

The GNU Lesser General Public License, Version 2.1, February 1999

and that's the whole page, main character energy from start to finish 🌈 this was generated for perl v5.42.3, dated 2026-07-23 β€” mwah, perfection, periodt πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from