Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unflatten method doesn't work with "toString" key #127

Open
yukienomiya opened this issue Jul 30, 2021 · 0 comments
Open

Unflatten method doesn't work with "toString" key #127

yukienomiya opened this issue Jul 30, 2021 · 0 comments

Comments

@yukienomiya
Copy link

Problem

The unflatten method doesn't work with a key named toString.

For example, starting with this object:

{
  "p5": {
    "y": "The y component of the vector",
    "toString": {
      "returns": "String: "
    }
  }
}

Then flatten it:

{
  'p5/y': 'The y component of the vector',
  'p5/toString/returns': 'String: '
}

And then unflatten it:

{
  "p5": {
    "y": "The y component of the vector"
  }
}

The toString key disappears.

Workaround

I ended up adding a prefix to all the keys while flattening the object (with the transformKey option), and then removing it after unflattening it again. To remove the prefix I used the map-obj library to map all the key and values from the original object to a new one, where the keys were substrings of the original ones.

jgallegos pushed a commit to jgallegos/flat that referenced this issue Oct 18, 2021
…ype key like constructor, toString, valueOf, etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant