Connecting to JSON (JavaScript Object Notation)
This connection allows you to transfer a static JSON file or a URL address, at which it will be received before building a report, as a data source.
JSON connector
When creating a new connection in the FastReport designer, it looks like this:
Setting | Description |
---|---|
Encoding | Sets the encoding in which the request for JSON will be processed, if a link to receive it is provided. |
JSON or URL | Sets static JSON or a link to receive JSON via API. |
JSON Schema | Sets the JSON schema. |
Headers | Sets the required HTTP headers for connecting to JSON via the API (optional). |
On the right side there are buttons for editing the field in a separate window.
If the JSON Schema value is empty, then when you click OK or Test connection, a schema will be automatically built using JSON.
If you change JSON or URL when the schema is already specified, FastReport will offer to update the schema.
JSON Editor Window
This window allows you to edit JSON:
Description of the editor window from left to right:
- Open file - allows you to open JSON and paste the contents of the file into the editor.
- Save file - allows you to save the contents of the editor to a file.
- Encoding - sets the encoding in which the JSON file will be opened.
- Formatting - enables JSON formatting, and also validates JSON against specifications.
Then there is the editor field where you can change the JSON text.
The "Word Wrap" checkbox will enable or disable word wrapping in the editor.
How the connection works
JSON is not a table, therefore FastReport does not treat a JSON connection as a data table.
Instead, FastReport treats each JSON array as a hierarchical data source with three fields:
Field | Description |
---|---|
index | Number of the item |
item | Item |
array | URL to the items array |
Any JSON array can be connected to the DataBand.
Then you can use fields from JSON in report objects.