Git Product home page Git Product logo

Comments (1)

rorosentrater avatar rorosentrater commented on August 16, 2024

idk if this issue is related to the #48 issue referenced but, I am also observing this issue. I think the root of the problem is because of the way list indexes are flat packed.

# Original dict A
{'foo': ['a', 'b', 'c']}

is flat packed as:

# Flat dict A
'foo_0': 'a',
'foo_1': 'b',
'foo_2': 'c',

Which is identical to the way the following dict would also be packed:

# Original dict B
{
    'foo': {
        '0': 'a',
        '1': 'b',
        '2': 'c',
    }
}

Which again is flat packed as:

# Flat dict A
'foo_0': 'a',
'foo_1': 'b',
'foo_2': 'c',

and so both of these flat packed formats are unpacked into the same structure (NOT desired, as you can see we started with 2 very different JSONs/dicts)

Maybe this could be solved by changing how list item indexes are flat packed? I have seen other libraries use this format foo[0]: 'a' for list indexes, leaving the foo_0': 'a' format unambiguously a dict only format representing the key 'foo' which itself has a nested dict with the key '0'.

Though the above approach creates another bug if implemented because then what do you do if the original dict looks like this?

{
    'IAmJustAKeyName[0]': 'Not a list item'
}

^ This may be an acceptable bug until someone figures out how to fix that edge case though as I think mixing up list indexes and keys named just '0' is a much more common problem than unintentionally casting a key named 'foo[0]' to a list item.

from flatten.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.