Making Arrays Or Objects

If you want a json editor, I suggest https://www.jsonblob.com or https://jsoncrack.com/editor

Creating Arrays

Arrays in OSL are 1-indexed collections that can hold any type of value.

// Simple array
numbers = [1, 2, 3, 4, 5]

// Array with expressions
base = 10
computed = [base * 1, base * 2, base * 3]  // [10, 20, 30]

// Mixed type array
mixed = [1, "text", true, {x: 10}]

// Array with computed values
vals = [1 + 1, "pre" ++ "fix", 10 * 2]  // [2, "prefix", 20]
// Note: ++ concatenates without spaces, so "pre" ++ "fix" becomes "prefix"

Creating Objects

Objects are collections of key-value pairs that can include computed values and methods.

Important Notes

  • Arrays are 1-indexed (first element is at index 1)

  • Objects can use self to reference their own properties

  • Both arrays and objects can contain any OSL data type

  • Values can be computed when creating arrays or objects

  • Methods can be included in objects using def() ->

Last updated

Was this helpful?