Scilab Website | Contribute with GitLab | Scilab Community | ATOMS toolboxes
Scilab Online Help
2026.1.0 - Português


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]")
--> // JSON object
--> fromJSON("{""status"": ""OK"", ""value"":12}")

 ans = [struct] with fields:

  status = "OK"
  value = 12

--> // JSON array
--> fromJSON("[1, 2, 3]")

 ans = [1x3 double]

   1.   2.   3.

--> // JSON null values
--> fromJSON("[1, 2, null]")

 ans = [1x3 double]

   1.   2.   Nan

--> fromJSON("[1, true, null]")

 ans = (3-elements list)

  (1) = 1
  (2) = %t
  (3) = []

--> // non-finite values
--> fromJSON("[NaN, Infinity, -Infinity]")

 ans = [1x3 double]

   Nan   Inf  -Inf   
    

See also

History

VersãoDescrição
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-2026 (Dassault Systèmes S.E.)
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:
Tue May 19 14:04:06 CEST 2026