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 8940425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:01:58+00:00 2026-06-15T11:01:58+00:00

I have some config files and the data format can’t be changed. One of

  • 0

I have some config files and the data format can’t be changed.

One of them looks like this:

root {
  configuration {
    field_a: "aaaa"
    field_b: "bbbb"
  }
  child {
    configuration {
        field_a: "aaa1"
        field_b: "bbb1"
    }
  }
  child {
    configuration {
        field_a: "aaa2"
        field_b: "bbb2"
    }
  }
}

What i need is to parse the file and save it as JSON objects:

{root: 
    {field_a:"aaaa",field_b:"bbbb"},
    children: [{field_a:"aaa", field_b:"bbb"}, ... ]
}

Is there any way to make it possible ?

  • 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-15T11:01:59+00:00Added an answer on June 15, 2026 at 11:01 am

    A quick thought:

    if the config is well indented and lined as the example:

    replace “{” and “}” s to make it like this:

    root:
      configuration:
        field_a: "aaaa"
        field_b: "bbbb"
      child:
        configuration:
            field_a: "aaa"
            field_b: "bbb"
    

    And now it’s a yaml format file!
    just transform from yaml to json by all means!

    import yaml
    import json
    
    s = "yamlstr"  # your yaml str
    data = yaml.load(s)
    jsondata = json.dumps(data)
    print jsondata
    

    UPDATE

    As the fact that child is a list, and both “root”, “configuration” and “child” seems to be keywords, change a bit and go for the workaround:

    make this happen:

    root:
      - configuration:
        field_a: "aaaa"
        field_b: "bbbb"
      - child:
        - configuration:
            field_a: "aaa1"
            field_b: "bbb1"
      - child:
        - configuration:
            field_a: "aaa2"
            field_b: "bbb2"
    

    and output python dict would be:

    {'root': [{'configuration': None, 'field_b': 'bbbb', 'field_a': 'aaaa'}, {'child': [{'configuration': {'field_b': 'bbb1', 'field_a': 'aaa1'}}]}, {'child': [{'configuration': {'field_b': 'bbb2', 'field_a': 'aaa2'}}]}]}
    

    Now do some simple programming and make it your structure 🙂

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

Sidebar

Related Questions

I have an object config which has some properties. I can export this ok,
Background: I have some data thats stored in the web.config files of about 100
In a complex project, I have many XML files like data files, config files
I have some configuration data in a config file that I read off disk
We have a set of tables and views that merely store some config data
I have some data in array format which I wrote to a file in
I have a project with some files which consist of config files with passwords
I have done some preliminary reading. Config files vs database tables Type to use
I have an awesome little function that looks like this: def verbose_print(message, *args, **kwargs):
In my app, I have a simple ASCII file which stores some config info

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.