Is there a way to add a JSON attribute?

I’ve found in the documentation that you can specify attribute of type json, but I couldn’t figure out how to let it be visible in the editor.

MyScript.attributes.add(‘myJson’, { type:‘json’ , title:‘jsonTest’ });

Is there something else that needs to be specified?

Hi @guzu,

Try this:

MyScript.attributes.add('jsonFile', { type: 'asset', assetType: 'json' });

@Leonidas According to pc.ScriptAttributes docs, type json is valid. Has this been changed?

Hmm good point, I have no idea actually.

I’ve always been using asset for JSON, much like the tutorial projects:

1 Like

Heeey. JSON attributes in the API (which is released too early) is for a more flexible attributes system. In a nutshell, it’s the equivalent of using a struct as a public attribute in Unity.

We can define a data object using JSON schema (eg a texture asset, a string for a name and a number for some value) and be able to create an array of those objects.

Still WIP :grimacing:



For the OP, if you would like to refer to a JSON file in the project like Leonidas has said, use an attribute of type asset and then use asssetType JSON. :slight_smile:

Thank you for clarification, @yaustar!

Edit: still I don’t understand why the type json is not accepted as a valid type, though :slight_smile: Even if it is an empty field, without supplying any asset/value to it.

Wow thanks everyone :+1: