diff --git a/src/Mapping.m b/src/Mapping.m index 062b744..90e3e3e 100644 --- a/src/Mapping.m +++ b/src/Mapping.m @@ -170,39 +170,36 @@ function print_mapping(obj, filename) obj = flatten_mapping(obj); - % print to screen be default; - output_is_json = false; + if nargin > 1 && strcmp(bids.internal.file_utils(filename, 'ext'), 'json') + output_is_json = true; + content = {}; + for i = 1:size(obj.mapping, 1) + input = obj.mapping(i); + input = rmfield(input, 'name_spec'); + content{i, 1} = struct('input', input, ... + 'output', obj.mapping(i).name_spec); + end + bids.util.jsonencode(filename, content); + return + end + + % print to screen by default + fid = 1; % what to separate input and output with left = ' '; separator = ' --> '; right = ' '; - if nargin < 2 - - fid = 1; - - elseif ~strcmp(bids.internal.file_utils(filename, 'ext'), 'json') - + if nargin > 1 fid = fopen(filename, 'Wt'); if fid == -1 error('Unable to write file %s.', filename); end - + % markdown table separators left = '| '; separator = ' | '; right = ' |'; - - elseif strcmp(bids.internal.file_utils(filename, 'ext'), 'json') - - output_is_json = true; - - content = {}; - - else - - fid = 1; - end header = ['