Skip to content

Commit

Permalink
Dont emit anything for empty JSON arrays & Release 1.0.3 (#56)
Browse files Browse the repository at this point in the history
Release 1.0.3
  • Loading branch information
Blacksmoke16 authored Apr 22, 2020
1 parent ee40e9e commit e8dafaf
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: oq
description: |
A performant, and portable jq wrapper thats facilitates the consumption and output of formats other than JSON; using jq filters to transform the data.
version: 1.0.2
version: 1.0.3

authors:
- George Dietrich <george@dietrich.app>
Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: oq
version: '1.0.2'
version: '1.0.3'
summary: A performant, and portable jq wrapper to support formats other than JSON
description: |
A performant, and portable jq wrapper thats facilitates the consumption and output of formats other than JSON; using jq filters to transform the data.
Expand Down
9 changes: 2 additions & 7 deletions spec/converters/xml_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,7 @@ describe OQ::Converters::Xml do
output.should eq(<<-XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
<a>
<foo/>
</a>
<a/>
</root>\n
XML
)
Expand Down Expand Up @@ -584,7 +582,6 @@ describe OQ::Converters::Xml do
output.should eq(<<-XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
<a/>
<b/>
<c/>
</root>\n
Expand All @@ -600,9 +597,7 @@ describe OQ::Converters::Xml do
output.should eq(<<-XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
<a>
<item/>
</a>
<a/>
</root>\n
XML
)
Expand Down
5 changes: 1 addition & 4 deletions src/converters/xml.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
module OQ::Converters::Xml
@@at_root : Bool = true

def self.deserialize(input : IO, output : IO, **args) : Nil
builder = JSON::Builder.new output
xml = XML::Reader.new input
Expand Down Expand Up @@ -137,7 +135,6 @@ module OQ::Converters::Xml
end

private def self.handle_object(builder : XML::Builder, json : JSON::PullParser, key : String? = nil, array_key : String? = nil, *, xml_item : String) : Nil
@@at_root = false
json.read_object do |k|
if k.starts_with?('@')
builder.attribute k.lchop('@'), get_value json
Expand All @@ -160,7 +157,7 @@ module OQ::Converters::Xml
array_key = array_key || xml_item

if json.kind.end_array?
builder.element(array_key) { } unless @@at_root
# If the array is empty don't emit anything
else
until json.kind.end_array?
builder.element array_key do
Expand Down
2 changes: 1 addition & 1 deletion src/oq.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require "./converters/*"

# A performant, and portable jq wrapper thats facilitates the consumption and output of formats other than JSON; using jq filters to transform the data.
module OQ
VERSION = "1.0.2"
VERSION = "1.0.3"

# The support formats that can be converted to/from.
enum Format
Expand Down

0 comments on commit e8dafaf

Please sign in to comment.