JSON - Maple Help

JSON (.json) File Format

JSON file format

Description

 • JSON (JavaScript Object Notation) is a lightweight text-based data standard for describing structured data made of key-value pairs and lists.
 • As a human-readable format, it offers an alternative to explicitly tagged structured data such as XML.
 • The JSON package provides tools for parsing and generating JSON expressions.
 • The general-purpose commands Import and Export also support this format.

Notes

 • Content-Type: application/json

Examples

Parse a JSON string as an expression.

 > $\mathrm{JSON}:-\mathrm{ParseString}\left("\left[1, 2, 3.265, 6.01, 7.373\right]"\right)$
 $\left[{1}{,}{2}{,}{3.265}{,}{6.01}{,}{7.373}\right]$ (1)

Import data from a file in JSON format.

 > $\mathrm{Import}\left("example/address.json",\mathrm{base}=\mathrm{datadir}\right)$
 ${table}{}\left(\left[{"founded"}{=}{1988}{,}{"companyName"}{=}{"Maplesoft"}{,}{"phoneNumbers"}{=}\left[{table}{}\left(\left[{"number"}{=}{"+1 \left(519\right) 747-2373"}{,}{"type"}{=}{"local"}\right]\right){,}{table}{}\left(\left[{"number"}{=}{"+1 \left(800\right) 267-6583"}{,}{"type"}{=}{"tollfree"}\right]\right){,}{table}{}\left(\left[{"number"}{=}{"+1 \left(519\right) 747-5284"}{,}{"type"}{=}{"fax"}\right]\right)\right]{,}{"address"}{=}{table}{}\left(\left[{"streetAddress"}{=}{"615 Kumpf Drive"}{,}{"country"}{=}{"Canada"}{,}{"postalCode"}{=}{"N2V 1K8"}{,}{"city"}{=}{"Waterloo"}{,}{"province"}{=}{"ON"}\right]\right)\right]\right)$ (2)

Export data to a JSON file in the home directory of the current user.

 > $\mathrm{Mouse}≔\mathrm{table}\left(\left["Genus"="Mus","Species"="musculus"\right]\right)$
 ${\mathrm{Mouse}}{≔}{table}{}\left(\left[{"Genus"}{=}{"Mus"}{,}{"Species"}{=}{"musculus"}\right]\right)$ (3)
 > $\mathrm{Mouse}\left["Family"\right]≔"Muridae"$
 ${{\mathrm{Mouse}}}_{{"Family"}}{≔}{"Muridae"}$ (4)
 > $\mathrm{Mouse}\left["Order"\right]≔"Rodentia"$
 ${{\mathrm{Mouse}}}_{{"Order"}}{≔}{"Rodentia"}$ (5)
 > $\mathrm{Mouse}\left["Class"\right]≔"Mammalia"$
 ${{\mathrm{Mouse}}}_{{"Class"}}{≔}{"Mammalia"}$ (6)
 > $\mathrm{Export}\left("mouse.json",\mathrm{Mouse},\mathrm{base}=\mathrm{homedir}\right)$
 ${81}$ (7)

References

 [RFC4627] Crockford, D., The application/json Media Type for JavaScript Object Notation (JSON), RFC 4627, July 2006.