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

Problem with list convertions #22

Open
stg- opened this issue Feb 23, 2018 · 3 comments
Open

Problem with list convertions #22

stg- opened this issue Feb 23, 2018 · 3 comments

Comments

@stg-
Copy link

stg- commented Feb 23, 2018

Hi there!

I'm facing a problem trying to import/export some data into etcd using etcdtool. Since lists are converted into json objects creating directories using the index as the key, when I load a json file with a list and then try to export the destination key, both json files differ.

Example:

# cat test.json 
{
  "mylist": [
    { "one": "uno"},
    {"two": "dos"}
  ]
}
# ./etcdtool-3.4 --peers="https://myetcd:2379" import -y /test ./test.json
# ./etcdtool-3.4 --peers="https://myetcd:2379" export /test
{
  "mylist": {
    "0": {
      "one": "uno"
    },
    "1": {
      "two": "dos"
    }
  }
}

It would be great to export the directory so the resulting json file is the same that was loaded (expected behavior: when all the keys in a directory are whole numbers, then convert them into a list). Maybe it can be added as an optional parameter (e.g. --keep-lists)?.

@ake-persson
Copy link
Owner

ake-persson commented Feb 23, 2018

Etcd only handles strings natively for a key, also it doesn't support lists per default this is simulated in this manner. I could add some logic that would assume that if there are only integer keys that it's a list.

It would also be possible to create an identifier like "list": "true" on import.

@stg-
Copy link
Author

stg- commented Feb 26, 2018

I'm using the import/export functions of etcdtool from different sources, therefore I need both jsons to be equal.
I assume the import will convert lists the way it does, so I think the import doesn't need an identifier. Just by adding an option to reconstruct the lists (if there are only integer keys, as you said) in the exported json file would be enough.

@ake-persson
Copy link
Owner

I'll look into adding an option for this like "--num-infer-list".

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

2 participants