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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:26:15+00:00 2026-06-14T22:26:15+00:00

I have some data that looks like YAML, but aint. Here is an example;

  • 0

I have some data that looks like YAML, but aint. Here is an example;

An instance of A
  objectID=123
  family=abc

An instance of A
  objectID=234
  family=bcd
  List of 4 X elements:
    An instance of X:
      objectID=222
      name=ccc
    An instance of X:
      objectID=333

And so on…

I need to find a way to make it looks more like this:

[
  {'name': 'An instance of A',
   'data': [
     {'objectID': 123,
      'family': 'abc'
     }
   ]
 },
 ...

I have tried to create some recursive function to parse this, but it ends up being a mess.

I’m not asking for a complete working example, but what is the best way to do this in python?
Self calling function? Using another lib (which I haven’t found yet)? Using another language to help me and embed the whole thing in python?

  • 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-14T22:26:16+00:00Added an answer on June 14, 2026 at 10:26 pm

    Use a stack, and push and pop items from it as you find more or fewer levels of indentation; each level on the stack holds the indentation depth and the entry:

    stack = [(0, {})]  # indentation level, top-level entry
    entry = stack[-1][1]
    
    for line in input:
        line = line.strip()
        if not line: continue
    
        indentation = len(input) - len(input.lstrip())
        if indentation > stack[-1][0]:  # indented further? New entry
            entry = stack[-1][1]['data'] = {}
            stack.append((indentation, entry)) # push
        else:
            while indentation < stack[-1][0]:  # indentation dropped
                del stack[-1]       # pop
                entry = stack[-1][1]
    
        # process line and add to entry
    
    result = stack[0][1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data that looks like this: [ { _id : ObjectId(4e2f2af16f1e7e4c2000000a), advertisers
I have some data that looks something like this... +----------+----------+----------+ | Column 1 |
I have some data in an XML element that looks like this: <?xml version=1.0
I have some data in a table that looks roughly like the following: table
I have some C# code that looks something like this System.Data.DataRow row; var table
I need to store some data that looks a little like this: xyz 123
Let's say I have some data in R that looks like this: c(0.11, NA,
I have some one-many normalized data that looks like this. a | x a
I have some data in an XML element that looks like this: <item value=category1,category2>Item
In Python I have some data that looks like this: A = [ (-9,

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.