Output formatting is not right in some arrays
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
- Better output, i.e. not showing memory addresses
- 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
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
Thank you for the detailed examples @piotrwiniarczyk-silvair. I will take a look at these cases to fully understand them ASAP.
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.
This has been released under v2.4.0.
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>
Sorry I forgot about XML - my mistake.
I will revisit that.