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

Output formatting is not right in some arrays #364

Open
piotrwiniarczyk-silvair opened this issue Oct 9, 2023 · 6 comments · Fixed by #366
Open

Output formatting is not right in some arrays #364

piotrwiniarczyk-silvair opened this issue Oct 9, 2023 · 6 comments · Fixed by #366
Labels
bug Something isn't working

Comments

@piotrwiniarczyk-silvair
Copy link

Describe the bug
The array is wrongly output. See repro.

To Reproduce

Output -

echo '{"u":[{"n":"A"},{"n":"B"}]}' | dasel -r json -w - 'u.all()'
echo '{"u":[{"n":"A"},{"n":"B"}]}' | dasel -r json -w - 'u'
echo '{"u":[{"n":"A"},{"n":"B"}]}' | dasel -r json -w - 

Output xml

echo '{"u":[{"n":"A"},{"n":"B"}]}' | dasel -r json -w xml 'u'
echo '{"u":[{"n":"A"},{"n":"B"}]}' | dasel -r json -w xml

while
echo '{"u":[{"n":"A"},{"n":"B"}]}' | dasel -r json -w xml 'u.all()'
seems to be better

Output csv

echo '{"u":[{"n":"A"},{"n":"B"}]}' | dasel -r json -w csv 'u.all()'
echo '{"u":[{"n":"A"},{"n":"B"}]}' | dasel -r json -w csv 'u.all().n'
Error: CSVParser.toBytes cannot handle type string

Expected behavior

  1. Better output, i.e. not showing memory addresses
  2. Maybe a page in the documentation how to extract an array to csv but using only some fields:
    echo '{"u":[{"n":"A"},{"n":"B","a":"1"}]}' | dasel -r json -w csv 'u'
    works, but trying to get a csv with column "n" only is too hard for me. Maybe this is related to above problems.

This also should not be like this:
echo '{"u":[{"n":"A"},{"n":"B","a":"1"}]}' | dasel -r json -w xml 'u.all()

Desktop (please complete the following information):

  • OS: Windows 11
  • dasel version v2.3.6
@piotrwiniarczyk-silvair piotrwiniarczyk-silvair added the bug Something isn't working label Oct 9, 2023
@piotrwiniarczyk-silvair
Copy link
Author

More on these.

One would expect this will work:

echo -e 'A,B,C\na,b,c\nd,e,f' | dasel -r csv -w csv
Error: CSVParser.toBytes cannot handle type []map[string]interface {}

The json seems to be reasonable.

echo -e 'A,B,C\na,b,c\nd,e,f' | dasel -r csv -w json
[
  {
    "A": "a",
    "B": "b",
    "C": "c"
  },
  {
    "A": "d",
    "B": "e",
    "C": "f"
  }
]

Same json output.

echo -e 'A,B,C\na,b,c\nd,e,f' | dasel -r csv -w json 'all().merge()'
[
  {
    "A": "a",
    "B": "b",
    "C": "c"
  },
  {
    "A": "d",
    "B": "e",
    "C": "f"
  }
]

Now csv to csv works.

echo -e 'A,B,C\na,b,c\nd,e,f' | dasel -r csv -w csv 'all().merge()'
A,B,C
a,b,c
d,e,f

@TomWright
Copy link
Owner

Thank you for the detailed examples @piotrwiniarczyk-silvair. I will take a look at these cases to fully understand them ASAP.

@TomWright
Copy link
Owner

Hey @piotrwiniarczyk-silvair , I have fixed this issue. To access the fix immediately please use the development version of dasel.
The fix will be included in the next release.

@TomWright
Copy link
Owner

This has been released under v2.4.0.

@piotrwiniarczyk-silvair
Copy link
Author

The csv is case fixed. The xml and - cases are not.

$ dasel --version
dasel version v2.4.0
echo '{"u":[{"n":"A"},{"n":"B"}]}' | dasel -r json -w - 'u.all()'
echo '{"u":[{"n":"A"},{"n":"B"}]}' | dasel -r json -w - 'u'
echo '{"u":[{"n":"A"},{"n":"B"}]}' | dasel -r json -w -
&{[n] map[n:A]}
&{[n] map[n:B]}
[0xc00017bb20 0xc00017bb60]
&{[u] map[u:[0xc00020e4e0 0xc00020e500]]}
echo '{"u":[{"n":"A"},{"n":"B"}]}' | dasel -r json -w xml 'u'
echo '{"u":[{"n":"A"},{"n":"B"}]}' | dasel -r json -w xml
[0xc00026b4e0 0xc00026b500]
<doc>
  <u>&{[n] map[n:A]}</u>
  <u>&{[n] map[n:B]}</u>
</doc>

Not sure about this one.

echo '{"u":[{"n":"A"},{"n":"B","a":"1"}]}' | dasel -r json -w xml 'u.all()'
<n>A</n>
<doc>
  <a>1</a>
  <n>B</n>
</doc>

@TomWright TomWright reopened this Oct 18, 2023
@TomWright
Copy link
Owner

Sorry I forgot about XML - my mistake.

I will revisit that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants