Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2025.1.0 - English


fromJSON

Convert JSON to a Scilab variable.

Syntax

result = fromJSON(jsonData)
result = fromJSON(jsonFilename, "file")

Arguments

jsonData
A string containing JSON data.

jsonFilename
A JSON file path.

result
If the string is a correct JSON, the result contains the Scilab variable.

Description

This function converts a string or a JSON file into a Scilab variable. NaN, Infinity and -Infinity are converted to %nan, %inf and -%inf. JSON null is converted to an empty matrix [] while it is converted to %nan in number arrays. Non-homogeneous data types or size arrays are converted into a list of elements.

Examples

// JSON object
fromJSON("{""status"": ""OK"", ""value"":12}")
// JSON array
fromJSON("[1, 2, 3]")
// JSON null values
fromJSON("[1, 2, null]")
fromJSON("[1, true, null]")
// non-finite values
fromJSON("[NaN, Infinity, -Infinity]")

See also

History

VersionDescription
6.1 Function introduced.
2023.0.0 Handling of tabs (ascii(9)) changed.
2024.1.0 NaN, -Infinity and Infinity values are now managed.
Report an issue
<< Web Tools Web Tools http_delete >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu May 22 12:51:06 CEST 2025