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

Support for unflattening (e.g. reverse operation) #9

Closed
aidansteele opened this issue Oct 1, 2019 · 2 comments
Closed

Support for unflattening (e.g. reverse operation) #9

aidansteele opened this issue Oct 1, 2019 · 2 comments

Comments

@aidansteele
Copy link

Hi,

Nice library! Have you considered adding support for reversing, i.e. unflattening? If I slightly change the example in the README:

input := `{ "one.two.0": "2a", "one.two.1": "2b", "side": "value" }`
nested, err := flatten.UnflattenString(input, "", flatten.DotStyle)

/*
nested == {
  "one": {
    "two": [
      "2a",
      "2b"
    ]
  },
  "side": "value"
}
*/
@jeremywohl
Copy link
Owner

Hmm, we lose information in flattening, would have to name appropriately.

Do you have a specific example use case?

@leslie-qiwa
Copy link

Unflattening should be useful in such a use case:

  1. I need a flattened json string to store all key values.
  2. I want to combine multiple sources of data into one json file, then add corresponding prefix for each flattened key. for example, {"facebook.username": "abc", "facebook.userpost": 5, "twitter.username": "xyz", "twitter.userpost": 20, ...}.

Unflattern may help user to reconstruct the struct and ease to operate if unmarshal is needed.

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

3 participants