From Lavish Software Wiki
Revision as of 18:13, 30 October 2018 by Lax (talk | contribs) (→‎Examples)
Jump to navigation Jump to search


Object Type Vitals
Defined By LavishScript
Inherits none
Reduces To same as AsString
Variable Object Type jsonvaluecontainer
Uses Sub-Types no
C/C++ Type void *

A jsonvalue is an immutable json value


  • string AsString: The contained value as a string
  • string AsJSON: The contained value as single-line JSON text
  • string AsJSON[multiline]: The contained value as multiline JSON text
  • ... Value: The contained value
  • string Type: The type of JSON object stored; one of: null, object, string, number, array, true, false, integer. Note that while the JSON standard does not differentiate between floating-point numbers and integers, LavishScript does




A walk-through of JSON usage
function main()
    ; initialize a json Object. Objects are denoted by {}
    ; json Objects contain "key":value pairs. The key is always a string, but any JSON value will do, including objects or arrays
    variable jsonvalue joMyValue={}  

    ; a variable that is a jsonvalue is really a "jsonvaluecontainer" https://www.lavishsoft.com/wiki/index.php/ObjectType:jsonvaluecontainer
    ; This container is holding an Object, currently empty.

    ; numeric types do not need any special formatting

    ; JSON strings are denoted by double quotes ""
    ; LavishScript also uses double quotes, so the inner quotes for the JSON must be escaped.
;    joMyValue:Set["SomeString","This is not valid and will produce a JSON error"]
    joMyValue:Set["SomeString","\"This is valid\""]

    ; Do note that the inner quotes are not actually stored as part of the JSON string, so when we show the values in this echo...
    echo ${joMyValue["SomeInteger"]}=12, ${joMyValue["SomeFloatingPoint"].Milli}=1.234, \"${joMyValue["SomeString"].Escape}\"=\"This is valid\"
    ; ... we put our own quotes there

    ; You can also have arrays. Arrays are denoted by []

    joMyValue["SomeArray"]:Add["\"First item!\""]
    joMyValue["SomeArray"]:Add["\"Second item!\""]
    echo \"${joMyValue[SomeArray].Get[1]}\"=\"First item!\" \"${joMyValue[SomeArray].Get[2]}\"=\"Second item!\"

    joMyValue["SomeArray"]:Add["{\"Ooooh\":\"You can also add entire objects\",\"Yep, and Arrays\":[1,2,3,4,5]}"]

    ; Here's the JSON
    echo JSON=${joMyValue.AsJSON}
JSON={"SomeArray":["First item!","Second item!",{"Ooooh":"You can also add entire objects","Yep, and Arrays":[1,2,3,4,5]}],"SomeFloatingPoint":1.234000,"SomeInteger":12,"SomeString":"This is valid"}

   ; File parsing is also built in!
   variable jsonvalue joFromFile

   echo ${joFromFile.AsJSON}

See Also

LavishScript Object Types