changeset 31722:d6b208b30d4c

maint: merge stable to default
author Rik <rik@octave.org>
date Tue, 10 Jan 2023 14:32:34 -0800
parents baa77a716bb8 (current diff) b4bde1e47dde (diff)
children 340d016c2edf
files
diffstat 2 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/jsonencode.cc	Sat Jan 07 11:12:28 2023 -0800
+++ b/libinterp/corefcn/jsonencode.cc	Tue Jan 10 14:32:34 2023 -0800
@@ -218,7 +218,7 @@
 {
   octave_map struct_array = obj.map_value ();
   octave_idx_type numel = struct_array.numel ();
-  bool is_array = (numel > 1);
+  bool is_array = (numel != 1);
   string_vector keys = struct_array.keys ();
 
   if (is_array)
--- a/test/json/jsonencode_BIST.tst	Sat Jan 07 11:12:28 2023 -0800
+++ b/test/json/jsonencode_BIST.tst	Tue Jan 10 14:32:34 2023 -0800
@@ -370,6 +370,19 @@
 %! obs  = jsonencode (data);
 %! assert (isequal (obs, exp));
 
+%!testif HAVE_RAPIDJSON <*63622>
+%! data = struct ('z', {});
+%! exp  = '[]';
+%! obs  = jsonencode (data);
+%! assert (isequal (obs, exp));
+%
+%!testif HAVE_RAPIDJSON <*63622>
+%! data.a = struct ('z', {});
+%! data.b = 1;
+%! exp  = '{"a":[],"b":1}';
+%! obs  = jsonencode (data);
+%! assert (isequal (obs, exp));
+
 %% another big Test
 %!testif HAVE_RAPIDJSON
 %! var1 = struct ('id', {0; 1; 2}, 'name', {'Collins'; 'Hays'; 'Griffin'});