Skip to content

Commit

Permalink
[feat] convert a single string variable to a string, without []
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Feb 1, 2025
1 parent 8d911de commit 681db4a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion savejson.m
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
%% -------------------------------------------------------------------------
function txt = obj2json(name, item, level, varargin)

if (iscell(item) || isa(item, 'string'))
if (iscell(item) || (isa(item, 'string') && numel(item) > 1))
txt = cell2json(name, item, level, varargin{:});
elseif (isa(item, 'jdict'))
txt = obj2json(name, item, level, varargin{:});
Expand Down
2 changes: 1 addition & 1 deletion test/run_jsonlab_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function run_jsonlab_test(tests)
test_jsonlab('empty string', @savejson, '', '""', 'compact', 1);
test_jsonlab('string escape', @savejson, sprintf('jdata\n\b\ashall\tprevail\t"\"\\'), '"jdata\n\b\ashall\tprevail\t\"\"\\"');
if (exist('string'))
test_jsonlab('string type', @savejson, string(sprintf('jdata\n\b\ashall\tprevail')), '["jdata\n\b\ashall\tprevail"]', 'compact', 1);
test_jsonlab('string type', @savejson, string(sprintf('jdata\n\b\ashall\tprevail')), '"jdata\n\b\ashall\tprevail"', 'compact', 1);
test_jsonlab('string array', @savejson, [string('jdata'), string('shall'), string('prevail')], '["jdata","shall","prevail"]', 'compact', 1);
end
test_jsonlab('empty name', @savejson, loadjson('{"":""}'), '{"":""}', 'compact', 1);
Expand Down

0 comments on commit 681db4a

Please sign in to comment.