JSON
Description
OSL provides powerful and flexible JSON handling with several unique features:
1-based array indexing
Dynamic JSON creation with variables and expressions
Built-in merging operations
Support for all OSL data types
Copy-based operations for data safety
JSON Creation
Basic Syntax
Merging with ++
The ++
operator merges arrays, objects, or strings:
Type Support
OSL JSON can contain any valid OSL type:
Numbers (integer and float)
Strings
Booleans
Arrays (1-indexed)
Objects
Functions
null
Important Notes
Arrays are 1-indexed (first element is at index 1)
Most operations create new copies rather than modifying in place
The
++
operator preserves values from the left operand on key conflictsJSON objects can contain functions and reference their own properties with
self
Expressions and variables in JSON are evaluated when the object is created
Nested objects and arrays are supported to any depth
All OSL data types can be stored in JSON structures
Last updated
Was this helpful?