RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact
  • License
  • Privacy

Learn

  • Docs
  • Blog
  • Benchmarks
  • RunMat vs MATLAB Online

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • jsondecode
    • jsonencode

jsondecode — Parse UTF-8 JSON text into MATLAB-compatible values in RunMat.

jsondecode(text) converts UTF-8 JSON text into MATLAB-compatible data values. Mapping of numbers, booleans, strings, objects, and arrays follows MATLAB semantics, including struct/cell expansion rules.

Syntax

value = jsondecode(text)

Inputs

NameTypeRequiredDefaultDescription
textAnyYes—JSON text as a char row vector, string scalar, or 1x1 string array.

Returns

NameTypeDescription
valueAnyDecoded MATLAB-compatible value (numeric/logical/string/struct/cell).

Errors

IdentifierWhenMessage
—Input text argument is not a character vector or string scalar.jsondecode: JSON text must be a character vector or string scalar
—Input text is not valid JSON.jsondecode: invalid JSON text
—A JSON numeric literal cannot be represented as a finite RunMat double.jsondecode: invalid JSON numeric literal
—Internal conversion from parsed JSON to RunMat values fails.jsondecode: internal conversion failed

How jsondecode works

  • Accepts a character vector or string scalar containing UTF-8 JSON data; leading and trailing whitespace is ignored.
  • JSON numbers decode to double-precision scalars or dense tensors that follow MATLAB's column-major layout.
  • JSON booleans decode to logical scalars or logical arrays with the same shape as the source JSON array.
  • JSON strings decode to char row vectors; homogeneous JSON arrays of strings become string arrays with matching dimensions.
  • JSON objects decode to scalar structs whose field names match the JSON keys; arrays of objects become cell arrays of structs that preserve element order.
  • JSON arrays decode to numeric, logical, or string arrays when every element shares the same type and the array is perfectly rectangular. Rectangular heterogeneous arrays (including those that mix null with other types) become cell arrays that preserve the original row/column layout, while irregular arrays fall back to 1-by-N cell vectors that keep element order.
  • JSON null decodes to the empty double []. When it appears inside a heterogeneous array it becomes a cell element containing [].
  • Invalid JSON raises jsondecode: invalid JSON text (...) with the underlying parser message.

Does RunMat run jsondecode on the GPU?

jsondecode does not execute on the GPU and has no provider hook. A numeric gpuArray is not JSON text and is rejected without downloading its payload.

GPU memory and residency

jsondecode is a host-text parser. RunMat does not represent text in numeric GPU buffers, so resident numeric handles are invalid input and reject before provider access; ordinary host text always produces host values.

Examples

Parsing a scalar number

value = jsondecode("42")

Expected output:

value = 42

Decoding a matrix of doubles

text = "[[1,2,3],[4,5,6]]";
matrix = jsondecode(text)

Expected output:

matrix =
     1     2     3
     4     5     6

Converting a JSON object into a struct

person = jsondecode('{"name":"Ada","age":37}');
disp(person.name);
disp(person.age)

Expected output:

Ada
    37

Decoding an array of objects into a cell array

text = '[{"name":"Ada","role":"Researcher"},{"name":"Grace","role":"Engineer"}]';
people = jsondecode(text);
people{1}.name
people{2}.role

Expected output:

people =
  1x2 cell array
    {1x1 struct}    {1x1 struct}

ans = 'Ada'
ans = 'Engineer'

Handling heterogeneous arrays with cell arrays

text = '["RunMat", 42, true]';
data = jsondecode(text)

Expected output:

data =
  1x3 cell array
    {"RunMat"}    {[42]}    {[1]}

Working with null and empty JSON values

value = jsondecode("null");
disp(value);
isempty(value)

Expected output:

[]
ans = logical 1

Using jsondecode with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how jsondecode changes the result.

Run a small jsondecode example, explain the result, then change one input and compare the output.

FAQ

What encodings does jsondecode support?⌄

JSON text must be UTF-8. RunMat preserves surrogate pairs and Unicode code points exactly as provided.

How are JSON objects represented?⌄

As scalar structs. Array-of-object JSON values become cell arrays of structs to preserve ordering.

What happens with JSON numbers that overflow double?⌄

Values must fit in the IEEE-754 double range. When a literal exceeds that range, the parser reports number out of range, which surfaces as a jsondecode: invalid JSON text (...) error.

Does jsondecode support comments or trailing commas?⌄

No. The JSON must adhere to RFC 8259. The builtin reports an error when encountering comments or other non-standard extensions.

How are JSON arrays of strings represented?⌄

Rectangular arrays of strings become string arrays. Mixed content falls back to cell arrays.

How does jsondecode treat null?⌄

null decodes to the empty double []. When it appears inside an otherwise homogeneous numeric array, the array is promoted to a cell array so that the [] value can be preserved alongside other elements.

Can I decode deeply nested arrays?⌄

Yes. Rectangular arrays of numbers, logicals, or strings produce dense tensors/string arrays with the appropriate dimensionality. Irregular arrays return nested cell arrays.

What if the input is not valid JSON?⌄

The builtin raises jsondecode: invalid JSON text (...) with the parser error message.

Does whitespace or newlines matter?⌄

Leading and trailing whitespace is ignored, and embedded newlines are permitted as long as the text remains valid JSON.

Related Io functions

Json

jsonencode

Net

accept · read · readline · tcpclient · tcpserver · write

Repl Fs

addpath · cd · copyfile · delete · dir · exist · fileattrib · fileparts · fullfile · genpath · getenv · getpref · isenv · isfile · isfolder · ispref · ls · matlabroot · memmapfile · mkdir · movefile · open · opentoline · path · pathsep · pcode · pwd · readstruct · rehash · restoredefaultpath · rmdir · rmpath · run · savepath · setenv · setpref · system · tempdir · tempname · uigetdir · uigetfile · uiputfile · unsetenv · userpath · what · winqueryreg · xmlread · xmlwrite

Tabular

arrayDatastore · csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · fileDatastore · parquetDatastore · parquetinfo · parquetread · readcell · readmatrix · readtable · readtimetable · spreadsheetImportOptions · writecell · writematrix · writetable · writetimetable · xlsread · xlswrite

Audio

audioinfo · audioread

Io

clc · diary · disp · display · format · input

Filetext

fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite · readlines · writelines

Archive

gunzip · gzip · unzip

Hdf5

h5disp · h5info · h5read · h5write · h5writeatt · hdf5info · hdf5read · hdf5write

Import

importdata · textscan

Mat

load · matfile · save

Http

sendmail · urldecode · urlencode · weboptions · webread · websave · webwrite

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how jsondecode is executed, line by line, in Rust.

  • View the source for jsondecode in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How jsondecode works
  • Does RunMat run jsondecode on the GPU?
  • GPU memory and residency
  • Examples
  • Parsing a scalar number
  • Decoding a matrix of doubles
  • Converting a JSON object into a struct
  • Decoding an array of objects into a cell array
  • Handling heterogeneous arrays with cell arrays
  • Working with null and empty JSON values
  • Using jsondecode with coding agents
  • FAQ
  • Related Io functions
  • Json
  • Net
  • Repl Fs
  • Tabular
  • Audio
  • Io
  • Filetext
  • Archive
  • Hdf5
  • Import
  • Mat
  • Http
  • Open-source implementation
  • About RunMat