]> git.corax.cc Git - toolbox/commitdiff
include/json: Make json_array_to_lines() use compact JSON notation
authorMatthias Kruk <m@m10k.eu>
Sat, 7 Jan 2023 08:38:54 +0000 (17:38 +0900)
committerMatthias Kruk <m@m10k.eu>
Sat, 7 Jan 2023 08:38:54 +0000 (17:38 +0900)
Because the whitespace that is printed by jq when outputting arrays
and objects in non-compact notation does not match the whitespace
that is expected by the test cases, the tests fail.

This commit modifies the `json_array_to_lines()' function so that it
outputs data in compact JSON notation, and changes the test cases so
they do not expect any whitespace at all.

include/json.sh
test/json_spec.sh

index 832116c564c4bd321f48c33875a0b934aab3095f..ba265e1ffafb6b2bcc344fbf8dfd1d6cb72daca7 100644 (file)
@@ -285,7 +285,7 @@ json_array_tail() {
 json_array_to_lines() {
        local array="$1"
 
-        if ! jq -r '.[]' <<< "$array"; then
+        if ! jq -c -r '.[]' <<< "$array"; then
                return 1
        fi
 
index 0fe5f292f5ac569479dbfcd47e6ed31330f43c01..35fe7790561dcb385cca4780243b085d1219cd7c 100644 (file)
@@ -390,9 +390,9 @@ Describe "json_array_to_lines()"
   End
 
   It "splits an object array to lines"
-    When call json_array_to_lines '[{"data": 1}, {"data": 2}]'
-    The first line of stdout should equal '{"data": 1}'
-    The second line of stdout should equal '{"data": 2}'
+    When call json_array_to_lines '[{"data":1}, {"data":2}]'
+    The first line of stdout should equal '{"data":1}'
+    The second line of stdout should equal '{"data":2}'
     The status should equal 0
   End
 End