Skip to main content

JSON

JSON (JavaScript Object Notation) is a lightweight data interchange format that is easy for humans to read and write and easy for machines to parse and generate.

In OasisW, JSON assets are used to store various types of structured data. Some use cases include:

  • Configuration files
  • Data for procedural generation
  • Game settings storage
  • Level design data

Accessing JSON Data in Scripts

To access data from a JSON asset in a script:

  1. Add the JSON asset as an attribute to your script.
  2. Access the resource of the JSON asset, which is the parsed object from the JSON data.

Example:

var JsonScript = pc.createScript('jsonScript');

// Define an attribute to hold the JSON asset
JsonScript.attributes.add('jsonAsset', { type: 'asset', assetType: 'json' });

JsonScript.prototype.initialize = function () {
if (this.jsonAsset) {
// Get the JSON asset's resource (an object)
const jsonData = this.jsonAsset.resource;

// Example: Accessing data from the JSON object
if (jsonData.someDataField) {
console.log("Data from JSON:", jsonData.someDataField);
}
}
};