-
-
Notifications
You must be signed in to change notification settings - Fork 18
OSL ‐ Json Handling
DanimalsTCGYT edited this page Aug 4, 2024
·
18 revisions
Json is a major part of large data storage in osl. It allows for much more complex data structures over basic variables
OSL has array documentation here: Array Documentation
Do not use spaces outside of quotation marks, it can mess up the parsing
object = {"key":"data","key2":"data2"}
array = ["data","data2","data3"]
// this is good json
object = {"key":"data", "key2":"data2"}
array = ["data", "data2", "data3"]
// this json could break your program
You can store arrays in arrays 😱
array = [["data","data2"],"data3","data4"]
Official JSON docs: Json Documentation
array[index] = "data"
// main recommended methods
object.key = "data"
object["key"] = "data"
// [] may be slower
// other methods
object."key" = "data"
object.["key"] = "data"
object.key("key") = "data"
object.item("key") = "data"
array = ["data",["data2","data3"]]
temp = array[2]
temp[2] = "data4"
array[2] = temp
If you run the above code, array is now equal to ["data",["data2","data4"]]
// newest syntax
item_of_array = array[index]
// legacy supported syntax
item_of_array = array.[index]
// oldest syntax
item_of_array = array.item(index)
// suggested:
key_of_object = object["key"]
// fastest
key of object = object.key
// legacy
key_of_object = object."key"
key_of_object = object.key("key")
// you can find an index of an item in an array in 2 ways
log array.index(value)
log array."value"
// both do the same thing
// only the first one allows you to use a variable in the input, the second is static
originOS is a web desktop gui with a self contained file system, programming languages, internet system and a whole lot of stuff an os should be able to do Use originOS here