Skip to main content
Version: Phaser v4.0.0

JSONFile

A single JSON File suitable for loading by the Loader. JSON files are parsed automatically upon load and the resulting data object is stored in the global JSON Cache, keyed by the file key. You can optionally supply a dataKey to extract and cache only a specific nested property from the JSON, rather than the entire file. JSON files are commonly used to store game configuration, level data, tilemap data, localization strings, or any other structured data your game requires.

These are created when you use the Phaser.Loader.LoaderPlugin#json method and are not typically created directly.

For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#json.

Constructor

new JSONFile(loader, key, [url], [xhrSettings], [dataKey])

Parameters

nametypeoptionaldescription
loaderPhaser.Loader.LoaderPluginNoA reference to the Loader that is responsible for this file.
keystring | Phaser.Types.Loader.FileTypes.JSONFileConfigNoThe key to use for this file, or a file configuration object.
urlobject | stringYesThe absolute or relative URL to load this file from. If undefined or null it will be set to <key>.json, i.e. if key was "alien" then the URL will be "alien.json". Or, can be a fully formed JSON Object.
xhrSettingsPhaser.Types.Loader.XHRSettingsObjectYesExtra XHR Settings specifically for this file.
dataKeystringYesWhen the JSON file loads only this property will be stored in the Cache.

Scope: static

Extends

Phaser.Loader.File

Source: src/loader/filetypes/JSONFile.js#L15
Since: 3.0.0

Inherited Methods

From Phaser.Loader.File:


Public Methods

onProcess

<instance> onProcess()

Description:

Called automatically by Loader.nextFile. This method parses the XHR response text as JSON. If a dataKey was specified when the file was added to the load queue, only the value at that dot-notation key path is stored in this.data; otherwise the entire parsed JSON object is stored. Once processing is complete it calls onProcessComplete.

Overrides: Phaser.Loader.File#onProcess

Source: src/loader/filetypes/JSONFile.js#L92
Since: 3.7.0


Inherited Members

From Phaser.Loader.File: