ParseFile - Maple Help

JSON

 ParseFile
 read JSON data from a file

 Calling Sequence ParseFile(source, opts)

Parameters

 source - string; file or URL to read from opts - (optional) options as specified below

Options

 • output=name

either table, record, or DataSeries. Specifies the data structure to use for parsed data corresponding to JSON objects (collections of key/value pairs). With output=table (the default), an object is encoded as table; with output=record, it is encoded as a record; with output=DataSeries, it is encoded as a DataSeries.

Description

 • The ParseFile(source) command reads JSON data from the file or URL source.
 If source is a file, it is closed after it is read.

Examples

Parse an input JSON file to a Maple table

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

Parse the same input JSON file to a Maple record

 > $\mathrm{JSON}:-\mathrm{ParseFile}\left(\mathrm{address},\mathrm{output}=\mathrm{record}\right)$
 ${{\mathrm{Record}}}_{{\mathrm{packed}}}{}\left({\mathrm{companyName}}{=}{"Maplesoft"}{,}{\mathrm{founded}}{=}{1988}{,}{\mathrm{address}}{=}{{\mathrm{Record}}}_{{\mathrm{packed}}}{}\left({\mathrm{...}}\right){,}{\mathrm{phoneNumbers}}{=}\left[{{\mathrm{Record}}}_{{\mathrm{packed}}}{}\left({\mathrm{...}}\right){,}{{\mathrm{Record}}}_{{\mathrm{packed}}}{}\left({\mathrm{...}}\right){,}{{\mathrm{Record}}}_{{\mathrm{packed}}}{}\left({\mathrm{...}}\right)\right]\right)$ (3)

Compatibility

 • The JSON[ParseFile] command was introduced in Maple 2015.