diff --git a/tool/lib/JSONLib.jq b/tool/lib/JSONLib.jq index d1beb96..7a34515 100644 --- a/tool/lib/JSONLib.jq +++ b/tool/lib/JSONLib.jq @@ -46,22 +46,14 @@ def colourEscapes: ); def _encodeJSONValuePlainPretty($indent; $currentDepth): - (if $indent > 0 then [range($indent * $currentDepth) | " "] | join("") else "" end) as $currentIndentDepthIndent | - (if $indent > 0 then [range($indent * ($currentDepth + 1)) | " "] | join("") else "" end) as $nextDepthIndent | - (if $indent > 0 then "\n" else "" end) as $currentIndentDepthNewline | - (if $indent > 0 then " " else "" end) as $currentIndentDepthSpace | + [range($indent * $currentDepth) | " "] | join("") as $currentIndentDepthIndent | + [range($indent * ($currentDepth + 1)) | " "] | join("") as $nextDepthIndent | + "\n" as $currentIndentDepthNewline | + " " as $currentIndentDepthSpace | . as $value | (. | type) as $valueType | - if $valueType == "null" then - "null" - elif $valueType == "boolean" then - if $value then "true" else "false" end - elif $valueType == "number" then - $value | tostring - elif $valueType == "string" then - $value | tojson - elif $valueType == "array" then + if $valueType == "array" then ($value | length) as $numValues | if $numValues > 0 then @@ -100,6 +92,8 @@ def _encodeJSONValuePlainPretty($indent; $currentDepth): else "{}" end + else + tojson end; def _encodeJSONValueColourCompact: @@ -158,10 +152,10 @@ def _encodeJSONValueColourPretty($indent; $currentDepth): def colourText($text; $kind): ansiLib::CSR + $escapes[$kind] + "m" + $text + ansiLib::CSR + "0m"; - (if $indent > 0 then [range($indent * $currentDepth) | " "] | join("") else "" end) as $currentIndentDepthIndent | - (if $indent > 0 then [range($indent * ($currentDepth + 1)) | " "] | join("") else "" end) as $nextDepthIndent | - (if $indent > 0 then "\n" else "" end) as $currentIndentDepthNewline | - (if $indent > 0 then " " else "" end) as $currentIndentDepthSpace | + ([range($indent * $currentDepth) | " "] | join("")) as $currentIndentDepthIndent | + ([range($indent * ($currentDepth + 1)) | " "] | join("")) as $nextDepthIndent | + "\n" as $currentIndentDepthNewline | + " " as $currentIndentDepthSpace | . as $value | (. | type) as $valueType |