JSON To MATLAB Array

Login

Email
Password

Don't have an account yet?

Go to Sign up

Input Data
Sample {{ showCoderInput ? 'Choose File' : 'Enter Data' }}

                                
Valid JSON Invalid JSON — Cannot convert to JSON Array
Output Data
{{ copied ? 'Copied!' : 'Copy to Clipboard' }} Download File
Properties
Convert JSON to MATLAB online — paste, edit, and download MATLAB.

Variable Name:
The MATLAB variable name for the output array.
Output Type:
Cell Array for mixed data; Numeric Matrix for numbers only; Struct Array for keyed objects.
String Delimiter:
Single Quote (') Double Quote (")
Output Options:
Header Comments Transpose
NaN / Missing:
NaN '' [] How to represent null / empty values in the output.
Convert Restart

JSON to MATLAB Array — Free Online MATLAB Array Converter

What Is MATLAB?

MATLAB (Matrix Laboratory) is a numerical computing environment and programming language developed by MathWorks. It is widely used in engineering, science, finance, and academic research for data analysis, signal processing, control systems, and machine learning.

Key properties:

PropertyDescription
Matrix-centricAll data is fundamentally a matrix (2D array)
Numeric focusOptimized for numerical computation
ToolboxesExtended functionality via domain-specific toolboxes
PlottingBuilt-in 2D/3D visualization
File formats.m scripts, .mat data files

What Is JSON?

JSON (JavaScript Object Notation) is a lightweight, human-readable text format defined by RFC 8259. It uses key-value pairs and ordered lists to represent structured data.

Why Convert JSON to MATLAB?

Use CaseDescription
Data importLoad JSON API responses or config files into MATLAB workspace
Research dataConvert experimental data stored as JSON into MATLAB arrays for analysis
Signal processingImport sensor data from JSON logs into MATLAB for filtering and FFT
Machine learningPrepare training data from JSON into MATLAB matrix format
SimulationLoad simulation parameters from JSON into MATLAB models
MigrationPort data from web/Python workflows into MATLAB
TestingGenerate MATLAB test fixtures from JSON samples

MATLAB Data Types for JSON Conversion

MATLAB has three primary data structures for representing JSON data. Choosing the right one depends on your data.

Cell Array

A cell array can hold mixed data types — strings, numbers, booleans, and nested cells. Use this when your JSON contains heterogeneous data.

data = {
   'Alice', 30, true;
   'Bob', 25, false;
   'Charlie', 35, true
};

AspectDetails
Best forMixed-type data (strings + numbers + booleans)
Accessdata{row, col} (curly braces)
FlexibilityEach cell can hold any type
JSON mappingDefault choice — handles all JSON types

Numeric Matrix

A numeric matrix (2D array) holds only numbers. Use this when your JSON contains purely numeric data — all strings and booleans are excluded.

data = [
   1, 3.14, 42;
   2, 2.72, 17;
   3, 1.41, 99
];

AspectDetails
Best forPurely numeric data (measurements, coordinates, matrices)
Accessdata(row, col) (parentheses)
PerformanceFastest — native MATLAB matrix operations
JSON mappingOnly numeric fields are included; non-numeric fields are skipped

Struct Array

A struct array uses named fields. Each element is a struct with field names matching the JSON object keys. Use this when you need key-based access.

data(1).name = 'Alice';
data(1).age = 30;
data(2).name = 'Bob';
data(2).age = 25;

AspectDetails
Best forKeyed objects where field names matter
Accessdata(1).name (dot notation)
ReadabilitySelf-documenting — field names preserved
JSON mappingJSON objects → struct fields

JSON-to-MATLAB Type Mapping

JSON TypeJSON ExampleCell ArrayNumeric MatrixStruct Field
String"hello"'hello'(excluded)'hello'
Integer42424242
Float3.143.143.143.14
Boolean truetruetrue1true
Boolean falsefalsefalse0false
Nullnull(see NaN option)NaN(see NaN option)
Object{"a": 1}Nested cell(excluded)Nested struct
Array[1, 2][1, 2]Row in matrixVector field

Core Features

1. Dual Input Modes

  • File Upload: Drag and drop or select a .json file.

  • Code Editor: Paste or type raw JSON with syntax highlighting and real-time validation.

2. Variable Name

Set the MATLAB variable name for the output. This becomes the assignment target in the generated code.

% Variable Name = "sensorData"sensorData = {...};

Rules:

  • Must start with a letter

  • Can contain letters, digits, and underscores

  • Case-sensitive

  • No spaces or special characters

3. Output Type

TypeWhen to Use
Cell ArrayMixed data (strings + numbers) — safest default
Numeric MatrixPurely numeric data (measurements, coordinates)
Struct ArrayKeyed objects where you need data(1).field access

Cell Array output:

myData = {
   'Alice', 30, true;
   'Bob', 25, false
};

Numeric Matrix output:

myData = [
   1, 30, 1;
   2, 25, 0
];

Struct Array output:

myData(1).name = 'Alice';
myData(1).age = 30;
myData(1).active = true;
myData(2).name = 'Bob';
myData(2).age = 25;my
Data
(2).active = false;

4. String Delimiter

OptionSyntaxNotes
Single Quote'hello'Traditional MATLAB syntax (all versions)
Double Quote"hello"Introduced in MATLAB R2017a for string arrays

For maximum compatibility, use Single Quote. Use Double Quote if you work with MATLAB's string type (R2017a+).

5. Output Options

Header Comments

Adds comments at the top of the output showing column headers and metadata:

% Generated by A.Tools — JSON To MATLAB Array
% Columns: name, age, active
% Rows: 3
myData = {...};

Transpose

Transposes the output matrix — rows become columns and columns become rows. Useful when:

  • You need data organized by column (variable) instead of by row (observation)

  • Feeding data into MATLAB functions that expect column vectors

  • Matching MATLAB's column-major convention

Without transpose:

data = [
   1, 2, 3;
   4, 5, 6
];
% 2 rows × 3 columns

With transpose:

data = [
   1, 4;
   2, 5;
   3, 6
];
% 3 rows × 2 columns

6. NaN / Missing Value Handling

Controls how JSON null and empty values are represented in MATLAB output:

OptionOutputBest For
NaNNaNNumeric matrices — isnan() filtering
'''' (empty string)Cell arrays with string data
[][] (empty array)General-purpose — MATLAB's "empty" convention

Example:

% JSON: {"a": 1, "b": null, "c": 3}

% NaN option:
data = [1, NaN, 3];

% '' option (cell array):
data = {1, '', 3};

% [] option:
data = {1, [], 3};

7. Privacy by Design

All processing runs entirely in your browser. No data is uploaded to any server.

How to Use This JSON to MATLAB Array Converter?

Step 1: Provide Your JSON Data

Choose one of two input methods:

  • Upload a file: Click "Choose File" and select a .json file, or drag it into the upload area.

  • Paste data: Click "Enter Data" to switch to the code editor. Paste your JSON array. A "Valid JSON" badge confirms correct formatting.

Important: The tool expects a JSON array.

Step 2: Configure MATLAB Output

Use the Properties panel on the right:

  1. Variable Name: Enter a valid MATLAB variable name (e.g., sensorData, results).

  2. Output Type: Select Cell Array (mixed), Numeric Matrix (numbers only), or Struct Array (keyed).

  3. String Delimiter: Choose Single Quote (compatible) or Double Quote (R2017a+).

  4. Output Options: Check Header Comments and/or Transpose as needed.

  5. NaN / Missing: Choose how null/empty values are represented.

Step 3: Convert

Click Convert. The MATLAB code appears in the "Output Data" panel.

Step 4: Copy or Download

  • Click Copy to Clipboard to paste into your .m file.

  • Premium users can click Download File to save.

Complete Example

Example — Cell Array

Input JSON:

[
   {"name": "Alice", "age": 30, "active": true},
   {"name": "Bob", "age": 25, "active": false},
   {"name": "Charlie", "age": 35, "active": true}
]

Configuration:

  • Variable Name: users

  • Output Type: Cell Array

  • String Delimiter: Single Quote

  • Header Comments: On

  • Transpose: Off

  • NaN / Missing: NaN

Output:

% Generated by A.Tools — JSON To MATLAB Array
% Columns: name, age, active

users = {
   'Alice', 30, true;
   'Bob', 25, false;
   'Charlie', 35, true
};

Example — Numeric Matrix

Input JSON:

[
   {"x": 1.0, "y": 2.5, "z": 0.8},
   {"x": 1.5, "y": 3.0, "z": 1.2},
   {"x": 2.0, "y": 3.5, "z": 0.5},
   {"x": 2.5, "y": 4.0, "z": 1.8}
]

Configuration:

  • Variable Name: coords

  • Output Type: Numeric Matrix

  • Transpose: On

Output:

coords = [
   1.0, 1.5, 2.0, 2.5;
   2.5, 3.0, 3.5, 4.0;
   0.8, 1.2, 0.5, 1.8
];

Example — Struct Array

Input JSON:

[
   {"sensor": "temp_01", "reading": 23.5, "unit": "celsius"},
   {"sensor": "temp_02", "reading": 19.8, "unit": "celsius"},
   {"sensor": "humid_01", "reading": 65.2, "unit": "percent"}
]

Configuration:

  • Variable Name: readings

  • Output Type: Struct Array

Output:

readings(1).sensor = 'temp_01';
readings(1).reading = 23.5;
readings(1).unit = 'celsius';
readings(2).sensor = 'temp_02';
readings(2).reading = 19.8;
readings(2).unit = 'celsius';
readings(3).sensor = 'humid_01';
readings(3).reading = 65.2;
readings(3).unit = 'percent';

Example — NaN Handling

Input JSON:

[
   {"id": 1, "score": 95, "bonus": 10},
   {"id": 2, "score": null, "bonus": 5},
   {"id": 3, "score": 88, "bonus": null}
]

Configuration:

  • Output Type: Numeric Matrix

  • NaN / Missing: NaN

Output:

data = [
   1, 95, 10;
   2, NaN, 5;
   3, 88, NaN
];

Filter NaN values in MATLAB:

% Remove rows with any NaN
cleanData = data(~any(isnan(data), 2), :);

jsondecode() vs. This Tool

MATLAB R2016b+ has a built-in jsondecode() function.

Using jsondecode() (Runtime)

jsonStr = fileread('data.json');
data = jsondecode(jsonStr);

Aspectjsondecode()
When to useDynamic JSON from files, APIs, user input
OutputAlways struct or cell array
CustomizationNo control over variable name, delimiter, NaN handling
PerformanceParses at runtime

Using This Tool (Code Generation)

AspectThis Tool
When to useStatic data, hardcoded arrays, testing, scripts
OutputChoose cell array, numeric matrix, or struct array
CustomizationVariable name, delimiter, transpose, NaN handling
PerformanceNo parsing overhead — data is literal MATLAB code

Real-World Use Cases

Sensor Data Import

% From JSON API response to MATLAB numeric matrix
sensorData = [
   1633036800, 23.5, 45.2, 1013.1;
   1633037100, 23.8, 44.8, 1013.0;
   1633037400, 24.1, 43.5, 1012.8
];

% Plot temperature over time
plot(sensorData(:,1), sensorData(:,2));
xlabel('Timestamp');
ylabel('Temperature (C)');

Experimental Results

results(1).trial = 1;
results(1).accuracy = 0.95;
results(1).loss = 0.12;
results(2).trial = 2;
results(2).accuracy = 0.97;
results(2).loss = 0.08;

Matrix Operations

% Numeric matrix from JSON — ready for linear algebra
A = [
   1, 2, 3;
   4, 5, 6;
   7, 8, 9
];

eigenvalues = eig(A);
rank_A = rank(A);
det_A = det(A);

Frequently Asked Questions (FAQ)

  • Does the tool upload my data?

    No. All conversion happens locally in your browser using JavaScript. Your data never leaves your device.

  • What is the difference between Cell Array, Numeric Matrix, and Struct Array?

    Cell Array holds mixed types (strings, numbers, booleans) — use for general JSON data. Numeric Matrix holds only numbers — use for pure numeric data. Struct Array uses named fields — use when you need data(1).fieldName access.

  • Should I use single or double quotes?

    Use Single Quote ('text') for maximum compatibility with all MATLAB versions. Use Double Quote ("text") only if you need MATLAB's string type (R2017a+).

  • What does the Transpose option do?

    It swaps rows and columns. Without transpose, each JSON object becomes a row. With transpose, each JSON field becomes a column vector — matching MATLAB's column-major convention.

  • How are null values handled?

    Choose from three options: NaN (numeric not-a-number), '' (empty string), or [] (empty array). NaN is best for numeric matrices; empty string for cell arrays; empty array for general use.

  • Can I use this with MATLAB Online?

    Yes. Copy the output and paste it into MATLAB Online or MATLAB desktop.

  • What input format is required?

    A JSON array. Arrays of objects produce the best results: [{"key": "value"}, ...]. Arrays of primitives are also supported.

  • Is there a file size limit?

    The tool processes data entirely in your browser. Files up to 10 MB typically convert without issues on modern hardware.

  • Can I use this on mobile?

    Yes. The tool is responsive and works on smartphones and tablets.

Featured Tools

Featured tools that you might find useful.

Popular Tools

List of popular tools that users love and frequently use.

New Tools

The latest tools added to our collection, designed for you.

Topics

The tools grouped by topics to quickly find what you need.
Free online Excel to JSON converter. Transform XLSX, XLS, XLSM files into JSON arrays, objects, or keyed formats instantly in your browser — no upload, 100% private.

Excel To JSON

Free online Excel to JSON converter. Transform XLSX, XLS, XLSM files into JSON arrays, objects, or keyed formats instantly in your browser — no upload, 100% private.
Free Excel to CSV converter. Convert XLSX, XLS, XLSM to CSV instantly in your browser. No upload, 100% private. Edit, transpose, deduplicate before exporting.

Excel To CSV

Free Excel to CSV converter. Convert XLSX, XLS, XLSM to CSV instantly in your browser. No upload, 100% private. Edit, transpose, deduplicate before exporting.
Free online Excel to SQL converter. Generate CREATE TABLE and INSERT statements from spreadsheets for MySQL, PostgreSQL, SQLite, and SQL Server. Supports batch insert, primary keys, and type inference.

Excel To SQL

Free online Excel to SQL converter. Generate CREATE TABLE and INSERT statements from spreadsheets for MySQL, PostgreSQL, SQLite, and SQL Server. Supports batch insert, primary keys, and type inference.
Free online Excel to ASCII table converter with 10 border styles (MySQL, Unicode, reStructuredText, and more). Add code comment wrappers in 8 languages. Supports text alignment. Client-side processing.

Excel To ASCII Table

Free online Excel to ASCII table converter with 10 border styles (MySQL, Unicode, reStructuredText, and more). Add code comment wrappers in 8 languages. Supports text alignment. Client-side processing.