Presets JSON
If you're creating an editing extension that supports static presets, you must create a Presets JSON file and upload it to the Developer Portal.
A Presets JSON file is a JSON file that defines the extension's presets. Canva uses this file to render the presets in the Edit image panel.
This topic explains how to create a Presets JSON file.
To begin, create a JSON file:
touch presets.json
This file must be named
presets.json
.In the JSON file, create an array:
[]
Then, for each preset that the extension supports, add an object to this array.
Each object must have the following properties:
Name | Type | Required | Description |
---|---|---|---|
id | string | Yes | A unique ID for the preset. |
label | string | Yes | |
asset | string | Yes | The file name of an asset uploaded to the extension’s Assets field. Canva uses this asset as the preset’s thumbnail. |
kind | string | No | The type of preset. The accepted values are ”simple” or ”customizable” . The default value is "customizable” . |
category | string | No |
The following snippet demonstrates the configuration of three presets:
[
{
"id": "invert",
"label": "Invert",
"asset": "invert.png"
},
{
"id": "grayscale",
"label": "Grayscale",
"asset": "grayscale.png"
},
{
"id": "sepia",
"label": "Sepia",
"asset": "sepia.png"
}
]
To avoid runtime errors, validate the JSON before uploading it to the Developer Portal.
To validate the JSON, follow these steps:
- 1.
- 2.Enter the JSON into the JSON instance field.
{
"type": "array",
"uniqueItems": true,
"items": {
"properties": {
"id": {
"type": "string",
"description": "A unique ID for the preset."
},
"label": {
"type": "string",
"description": "A human readable label for the preset or the key of a localized label.."
},
"asset": {
"type": "string",
"description": "The file name of an asset uploaded to the extension’s 'Assets' field. Canva uses this asset as the preset’s thumbnail."
},
"kind": {
"type": "string",
"description": "The type of preset. The default value is 'customizable'.",
"enum": ["simple", "customizable"],
"default": "customizable"
},
"category": {
"type": "string",
"description": "A human readable label for a preset's category or the key of a localized label."
}
},
"required": ["id", "label", "asset"],
"additionalProperties": false
}
}
If an extension supports dynamic presets, Canva ignores the Presets JSON file, so if the extension's Use dynamic presets option is enabled, disable it.
- 1.Navigate to an app via the Developer Portal.
- 2.From the Extensions page, expand the Editing panel.
- 3.Upload the JSON file to the Assets field.
[
{
"id": "invert",
"label": "Invert",
"asset": "invert.png"
},
{
"id": "grayscale",
"label": "Grayscale",
"asset": "grayscale.png"
},
{
"id": "sepia",
"label": "Sepia",
"asset": "sepia.png"
}
]
Last modified 1yr ago