From 348334c67f8be5be098e93167d63355a6fa92763 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Wed, 22 Apr 2020 11:06:35 -0400 Subject: [PATCH] Dont emit anything for empty JSON arrays Release 1.0.3 --- shard.yml | 2 +- snap/snapcraft.yaml | 2 +- spec/converters/xml_spec.cr | 9 ++------- src/converters/xml.cr | 5 +---- src/oq.cr | 2 +- 5 files changed, 6 insertions(+), 14 deletions(-) diff --git a/shard.yml b/shard.yml index 4375bf3..04b9177 100644 --- a/shard.yml +++ b/shard.yml @@ -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 diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 1b0d9f7..473f662 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -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. diff --git a/spec/converters/xml_spec.cr b/spec/converters/xml_spec.cr index 986626f..8f5e8c3 100644 --- a/spec/converters/xml_spec.cr +++ b/spec/converters/xml_spec.cr @@ -418,9 +418,7 @@ describe OQ::Converters::Xml do output.should eq(<<-XML - - - + \n XML ) @@ -584,7 +582,6 @@ describe OQ::Converters::Xml do output.should eq(<<-XML - \n @@ -600,9 +597,7 @@ describe OQ::Converters::Xml do output.should eq(<<-XML - - - + \n XML ) diff --git a/src/converters/xml.cr b/src/converters/xml.cr index 87c74f4..7f61b4f 100644 --- a/src/converters/xml.cr +++ b/src/converters/xml.cr @@ -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 @@ -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 @@ -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 diff --git a/src/oq.cr b/src/oq.cr index f224212..7ffbece 100644 --- a/src/oq.cr +++ b/src/oq.cr @@ -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