Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

JSON Structure

Adam Martin edited this page Feb 8, 2015 · 3 revisions

Overview

Entities are loaded from and saved to streams via JSON. All JSON streams have a root object {} with 1 or more top-level child nodes. The order of the top-level child nodes isn't important except for the requirement that only 1 of each node can exist per file. Multiple streams can define the same top-level child node and each will be parsed in order. If a resource is referenced in a component, it need to be parsed before the component can get a reference..

Top-level Child Nodes

Top-level child nodes can only be of a few types:

Entities

The value of this top-level child node is an array [] of entity objects {}. An entity object describes the components and meta data (e.g name, id, transform) of that entity.

{
  "entities": [
    {
      "name": "",
      "id": 1,
      "component_type": {
        "resource_type": {
          "property1": "aaa",
          "property2": 1,
          "property3": true
        },
        "component_property": "value"
      },
      "component_type2": {
        "component_property": 1
      },
      "transform": {
        "x": 0,
        "y": 0,
        "z": 0
      }
    }
  ]
}

Each component that an entity has is described as a property "": inside the entity object {}. The value of each component property "": is an object {}. The properties "": of that object are passed to the component parser to create the component.

Resources

The value of this top-level child node is an object {} with resource_type (e.g. mesh, audio buffer, image, text file) as property "": names. Each resource_type property's value is an array [] of objects {} describing the resource to load.

{
  "resources": {
    "resource_type": [
      {
        "name": "meshx",
        "source": "disk",
        "filename": "meshx.obj"
      }
    ]
  }
}

Required properties "": for the resource object {} are "name", "source", and "filename", other properties are optional and per resource type. "Name" is used by components to get a reference to the resource from the resource loader and "filename" is the name of the file to load from disk if "source" is "disk".

Full Exmaple

{
  "entities": [
    {
      "name": "",
      "id": 1,
      "component_type": {
        "resource_type": {
          "property1": "aaa",
          "property2": 1,
          "property3": true
        },
        "component_property": "value"
      },
      "component_type2": {
        "component_property": 1
      },
      "transform": {
        "x": 0,
        "y": 0,
        "z": 0
      }
    }
  ],
  "resources": {
    "resource_type": [
      {
        "name": "meshx",
        "filename": "meshx.obj"
      }
    ]
  }
}