From 73c7ba2b9f9801b4cfdd67ef51ddf3e512bb1f4d Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sat, 7 Jan 2023 17:38:54 +0900 Subject: [PATCH] include/json: Make json_array_to_lines() use compact JSON notation 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 | 2 +- test/json_spec.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/json.sh b/include/json.sh index 832116c..ba265e1 100644 --- a/include/json.sh +++ b/include/json.sh @@ -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 diff --git a/test/json_spec.sh b/test/json_spec.sh index 0fe5f29..35fe779 100644 --- a/test/json_spec.sh +++ b/test/json_spec.sh @@ -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 -- 2.47.3