Initializing help system before first use

# jsonread

Purpose
Initialise a Mosel entity from a JSON data file.
Synopsis
`procedure jsonread(fname:text|string, mosobj:*)`
`procedure jsonread(fname:text|string, mosobj:*, taid:integer)`
Arguments

fname | Name of a JSON file
mosobj | A Mosel entity
taid | Type ID of a one-dimension array indexed by strings

Example
The following example can be used to read a JSON file which structure is unknown:

    declarations
      arrtype=dynamic array(string) of any
      doc:any
    end-declarations
    jsonread("myfile.json",doc,arrtype.id)

Further information
1. This procedure accepts basic types ( integer, real, boolean, string), native types compatible with from/tostring ( e.g. text or date, they are initialised from json strings), records (only public fields of supported types are populated from the corresponding json object members), one-dimension arrays indexed by strings (they are populated from json objects those members are used as indices for the array), lists of compatible types (populated from json arrays) and unions. Unsupported entities are silently ignored ( e.g. sets and incompatible arrays) and entries in the JSON document that do not correspond to an expected entry are also ignored.
2. Unions have a special handling: they can be initialised with a scalar (numbers, booleans or strings that are stored as text if the type is available), an object if the union itself is already a field of a record or an array cell (in this case the union takes the type of the structure that includes it), or an array that is mapped to a list of any.
3. When calling the second form of the procedure, the provided type ID (that must be a one-dimension array indexed by strings) is used to store objects.
4. Although basic types are supported the routine cannot initialise a scalar of a basic type: its input parameter must be a record, an array, a union, a variable of a native type (supporting serialisation) or a list.
5. The procedure does not reset its input parameter: in particular when initialising a list, the values from the JSON file will be appended to the existing content. Note that the special value null from the JSON data might be applied to lists, arrays, records and unions to reset these entities.
6. An IO error will be raised if the source file cannot be accessed or if a parsing error occurs.
Related topics
jsonwrite.
Module
mmhttp
Parent Topic Procedures and functions

© 2001-2026 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.