Showing revision 2.4

jdict

Universal Dictionary Interface for MATLAB/Octave

A powerful, xarray-inspired data structure that combines the flexibility of Python dictionaries with MATLAB's numerical computing power. Navigate complex hierarchical data effortlessly.

🚀 Unified Access

Works seamlessly with structs, containers.Map, and dictionaries

🎯 JSONPath Support

Query nested data with powerful JSONPath expressions

🔬 Dimension Labels

xarray-like dimension indexing for scientific data

âš¡ Attribute Storage

Attach metadata to any level of your data hierarchy

Scroll to explore

Getting Started

Simple, Intuitive Syntax

Access nested data structures with clean, readable syntax. No more deep struct navigation!

% Create a complex nested structure
data = struct('experiments', ...
    struct('trial1', rand(100, 64), 'metadata', ...
        struct('date', '2025-01-01', 'subject', 'P001')));

jd = jdict(data);

% Clean navigation
subject = jd.('experiments').('trial1').('metadata').('subject')()

% Or use JSONPath for deep queries
subject = jd.('$.experiments.trial1.metadata.subject')()

Metadata Management

Attach Attributes Anywhere

Store metadata like dimension names, units, and descriptions alongside your data. Perfect for scientific datasets!

% Create EEG data
eeg_data = rand(1000, 64, 50);  % time x channels x trials
jd = jdict(eeg_data);

% Attach metadata using curly braces (MATLAB)
jd{'dims'} = {'time', 'channels', 'trials'};
jd{'units'} = 'microvolts';
jd{'sampling_rate'} = 1000;

% Read attributes
dims = jd{'dims'}          % → {'time', 'channels', 'trials'}
units = jd{'units'}        % → 'microvolts'

xarray-Inspired

Dimension-Based Selection

Select data using dimension names instead of numeric indices. Make your code self-documenting!

% Setup multidimensional data
jd = jdict(rand(1000, 64, 50));
jd{'dims'} = {'time', 'channels', 'trials'};

% Select by dimension name - so much clearer!
first_100 = jd.time(1:100);           % First 100 timepoints
channel_5 = jd.channels(5);          % Just channel 5
subset = jd.time(1:500).trials(1:10);  % Chain selections!

% No more confusing: data(1:100, :, :) vs data(:, 5, :) ✨

Advanced Features

Smart Struct Array Handling

Combine dimension selection with struct field access. Get data from multiple struct elements at once!

% Create 2x3 struct array
sa = repmat(struct('name', 'exp', 'data', rand(10, 5)), 2, 3);
jd = jdict(sa);
jd{'dims'} = {'experiments', 'conditions'};

% Select row 1, then get all names
names = jd.experiments(1).('name')();
% → {'exp', 'exp', 'exp'} from all 3 structs in row 1

% Access specific element's data
data_point = jd.experiments(1).('data')(2);
% → data from 2nd element in row 1

Powerful Queries

JSONPath Deep Search

Use JSONPath expressions to query complex nested structures. Find data anywhere in your hierarchy!

% Load complex REST API data
jd = jdict('https://api.example.com/data.json');

% Deep search with '..' operator
all_names = jd.('$..name')();      % Find all 'name' fields
all_ids = jd.('$..id')();          % Find all 'id' fields

% Array indexing in path
first = jd.('$.results[0].data')();

% Combine with attribute access
jd.('$.results[0]'){'processed'} = true;

Flexible Metadata

Attributes at Any Level

Attach different metadata to different parts of your data structure. Each subfield can have its own attributes!

% Complex neuroimaging dataset
jd = jdict(struct('eeg', rand(1000,64), 'fmri', rand(100,100,50)));

% Different dims for different data types
jd.('eeg'){'dims'} = {'time', 'channels'};
jd.('eeg'){'units'} = 'uV';

jd.('fmri'){'dims'} = {'x', 'y', 'z'};
jd.('fmri'){'units'} = 'BOLD';

% Use dimension names for each modality
eeg_snippet = jd.('eeg').time(1:100);
fmri_slice = jd.('fmri').z(25);

Ready to Use

Get Started with jdict

Part of the JSONLab toolbox — one of MATLAB's most popular JSON parsers.

Installation

% Download JSONLab from GitHub
git clone https://github.com/NeuroJSON/jsonlab.git

% Add to MATLAB path
addpath('/path/to/jsonlab');

Key Methods

jd.('key') — Navigate
jd{'attr'} — Get/set attributes
jd.dim(indices) — Select by dimension
jd.tojson() — Export to JSON
jd.keys() — List subfields
jd.v(i) — Array indexing

Created by Qianqian Fang • Part of the NeuroJSON Project

Powered by Habitat