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

  • SEARCH
  • Home
  • 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 9100805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:57:30+00:00 2026-06-17T00:57:30+00:00

YAML has inheritance. The most clear example I have ever seen is here: http://blog.101ideas.cz/posts/dry-your-yaml-files.html

  • 0

YAML has inheritance. The most clear example I have ever seen is here: http://blog.101ideas.cz/posts/dry-your-yaml-files.html

I need something more complex: I need to override object’s object’s property. Here is an example:

database: &default
  server:
    ip: 192.168.1.5
    port: 2000
  db_name: test
  user: 
    name: root
    password: root

# database foo differs from default by only its port and user password
foo_database:
  <<: *default
  server:
    port: 2001
  db_name: foo
  user:
    password: foo_root

I want to get this result:

foo_database.server.ip -> 192.168.1.5
foo_database.server.port -> 2001
foo_database.db_name -> foo
foo_database.user.name -> root
foo_database.user.password -> foo_root

But if you declare like this, you will get these properties incorrect (according to expected values):

foo_database.server.ip -> will be None
foo_database.user.name -> will be None

because new “server” object has only “port” property and it overrides whole old “server” object.

How do I get the kind of inheritance which I want to achieve?

Edit

Here is my exact intention with a working code in LiveScript:

config = 
  default: 
    ip: \192.168.1.5
    port: 2000
    name: \root 
    password: \root 
    db:
      name: \default
      location: \LA

  foo-database:~ -> @default `merge` do 
    ip: \11.11.11.11
    db:
      name: \my-foo 

  bar-database:~ -> @foo-database `merge` do 
    password: \1234 
    db:
      location: \SF

config.default 
# => {"ip":"192.168.1.5","port":2000,"name":"root","password":"root","db":{"name":"default","location":"LA"}}
config.foo-database  
# => {"ip":"11.11.11.11","port":2000,"name":"root","password":"root","db":{"name":"my-foo","location":"LA"}}
config.bar-database  
# => {"ip":"11.11.11.11","port":2000,"name":"root","password":"1234","db":{"name":"my-foo","location":"SF"}}
  • 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-06-17T00:57:32+00:00Added an answer on June 17, 2026 at 12:57 am

    Unfortunately, you can’t get the kind of “inheritance” you want to achieve because YAML’s “inheritance” is more like a form of “merging hashes”.

    Expanding out your configuration at the point you use the *default alias, you have:

    foo_database:
      server:
        ip: 192.168.1.5
        port: 2000
      db_name: test
      user: 
        name: root
        password: root
    

    If you use hashes with the same keys afterwards, they will completely overwrite the hashes declared earlier, leaving you with (excuse the formatting):

    foo_database:
    

      server:
        ip: 192.168.1.5
        port: 2000
      db_name: test
      user: 
       name: root
       password: root  
    

      server:
        port: 2001
      db_name: foo
      user:
        password: foo_root
    

    So, in your case, it would seem that since the config is not exactly the same, DRYing up your configuration using anchors and aliases probably isn’t the right approach.

    More references on this issue below:

    • Rake, YAML and Inherited Build Configuration
    • Merging hashes in yaml conf files

    Edit

    If you really wanted to, I think you could reconfigure your YAML as below to get exactly what you want, but in your case, I would say the extra obfuscation isn’t worth it:

    server_defaults: &server_defaults
      ip: 192.168.1.5
      port: 2000
    
    user_defaults: &user_defaults
      name: root
      password: root
    
    database: &default
      server:
        <<: *server_defaults
      db_name: test
      user: 
        <<: *user_defaults
    
    foo_database:
      <<: *default
      server:
        <<: *server_defaults
        port: 2001
      db_name: foo
      user:
        <<: *user_defaults
        password: foo_root
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little Problem with Doctrine and Yaml: Here is my Model: Keyword:
Is there any plugin to synchronize two YAML files ? For example file1 has
Has anyone ever found an error like this? File C:\Python27\lib\site-packages\yaml\parser.py, line 439, in parse_block_mapping_key
I have a Google App Engine app - http://mylovelyapp.appspot.com/ It has a page -
Hi i have a yaml file like so --- data: - date: 2004-06-11 description:
Here is a portion of my app.yaml file: handlers: - url: /remote_api script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
I have code that relies heavily on yaml for cross-language serialization and while working
http://cpansearch.perl.org/src/MSTROUT/YAML-0.84/lib/YAML/Loader/Base.pm If I am hitting die 'load() not implemented in this class.'; What does
Symfony has turned me on to the power of YAML . It used to
This question has been asked before: Read and write YAML files without destroying anchors

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.