Skip to content

Commit

Permalink
Bug fix to write_json
Browse files Browse the repository at this point in the history
Correctly handle sparse logical `binary` field when encoding as JSON.
  • Loading branch information
tsipkens committed May 7, 2024
1 parent 2cc4396 commit e5d4616
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions +tools/write_json.m
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@

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

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

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

% Binary field of Aggs structure is sparse logical.
% Convert of logical, as sparse structure cannot be stored.
if isfield(var, 'binary')
for ii=1:length(var)
var(ii).binary = full(var(ii).binary);
end
end

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

0 comments on commit e5d4616

Please sign in to comment.