Skip to content

Commit e5d4616

Browse files
committed
Bug fix to write_json
Correctly handle sparse logical `binary` field when encoding as JSON.
1 parent 2cc4396 commit e5d4616

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

+tools/write_json.m

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11

22
% WRITE_JSON Used to write structures for JSON files.
3-
%
4-
% NOTE: There is a known issue on Mac systems where logicals cannot be
5-
% written to the files. Omit the corresponding fields for those cases.
3+
% NOTE: Saving large aggregate structures can be slow.
64
%
75
% AUTHOR: Timothy Sipkens
86

97
function [t2,t0] = write_json(var, fname)
108

119
fid = fopen(fname,'wt'); % open file, overwriting previous text
1210

11+
% Binary field of Aggs structure is sparse logical.
12+
% Convert of logical, as sparse structure cannot be stored.
13+
if isfield(var, 'binary')
14+
for ii=1:length(var)
15+
var(ii).binary = full(var(ii).binary);
16+
end
17+
end
1318

1419
%-- Encode json ----------------------------------------------------------%
1520
t0 = jsonencode(var); % generate json text using built-in function

0 commit comments

Comments
 (0)