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

Clarify mapping of arrays to XML #17

Closed
nichtich opened this issue Jul 18, 2019 · 2 comments · Fixed by #18
Closed

Clarify mapping of arrays to XML #17

nichtich opened this issue Jul 18, 2019 · 2 comments · Fixed by #18
Labels
format:xml kind:bug An existing feature isn't doing something correctly
Milestone

Comments

@nichtich
Copy link
Contributor

Raised at #16 (comment) there are some edge cases when mapping JSON with arrays to XML. In the end the handling is arbitrary convention but it should be consistent. Some examples:

$ echo '[]' | oq -o xml .
<root/>

makes sense

$ echo '["x",{}]' | oq -o xml .
<root><item>x</item><item/></root>

this surprised me. Why support arrays on the root level at all?

$ echo '{"a":[],"b":{},"c":null}' | oq -o xml . 
<root><b/><c/></root>

why no <a/>?

$ echo '{"a":[[]]}' | oq -o xml .
<root><a/></root>

wtf?

$ echo '{"x":[1,[2,[3]]]}' | oq . -o xml
<root>
  <x>1</x>
  <x>
    <item>2</item>
    <item>
      <item>3</item>
    </item>
  </x>
</root>

Ok, there is some logic here

@nichtich nichtich changed the title Clarify mapping of arrays to Clarify mapping of arrays to XML Jul 18, 2019
@Blacksmoke16 Blacksmoke16 added format:xml kind:bug An existing feature isn't doing something correctly status:wip labels Jul 18, 2019
@Blacksmoke16
Copy link
Owner

The third case there is probably since the array is empty, so it doesn't add any elements. Would just want to emit an empty tag in that case. Which would make sense why the fourth has the empty tag since it has an element.

Nested array stuff like this should get better in my refactor.

@Blacksmoke16 Blacksmoke16 added this to the 0.2.0 milestone Jul 18, 2019
@Blacksmoke16
Copy link
Owner

Blacksmoke16 commented Jul 19, 2019

Boy, what a PITA. This is what I got working currently. Probably going to call it good enough.

echo '[]' | ./bin/oq -o xml .
<?xml version="1.0" encoding="UTF-8"?>
<root/>
echo '["x",{}]' | ./bin/oq -o xml .
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <item>x</item>
  <item/>
</root>

Just because it's prob easier than not allowing it. Maybe useful concating a bunch of stuff together? idk.

echo '{"a":[],"b":{},"c":null}' | ./bin/oq -o xml .
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <a/>
  <b/>
  <c/>
</root>
echo '{"a":[[]]}' | ./bin/oq -o xml .
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <a>
    <item/>
  </a>
</root>
echo '{"x":[1,[2,[3]]]}' | ./bin/oq . -o xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <x>1</x>
  <x>
    <item>2</item>
    <item>
      <item>3</item>
    </item>
  </x>
</root>
echo '{"x":[1,2,3]}' | ./bin/oq . -o xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <x>1</x>
  <x>2</x>
  <x>3</x>
</root>

Seems sufficient enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
format:xml kind:bug An existing feature isn't doing something correctly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants