Libraries.Data.Formats.JavaScriptObjectNotation Documentation

This class can read in JavaScriptObjectNotation (JSON) formatted data from text values or from disk. When it reads them in, the data is stored inside this object. Alternatively, this class allows the programmer to set a listener object that can receive information about how the JSON file is being parsed as it occurs.

Example Code

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
action Main
     text dq = ""
     dq = dq:GetDoubleQuote()
     text myValue = "{" + dq + "data" + dq + ": [21.5, 22.7, 23.9]}"
     JavaScriptObjectNotation json
     json:Read(myValue)
     output json:ToText()
     output json:GetValue("data")
     i = 0
     repeat while i < json:GetSize()
         JavaScriptObjectNotation array = json:Get(i)
         if array:GetKey() = "data"
             j = 0
             repeat while j < array:GetSize()
                 JavaScriptObjectNotation item = array:Get(j)
                 output item:GetNumber()
                 j = j + 1
             end
         end
         i = i + 1
     end
end
end

Inherits from: Libraries.Language.Object

Actions Documentation

Add(Libraries.Data.Formats.JavaScriptObjectNotation object)

Use this method to add a nested JavaScriptObjectNotation object. The object must already have a key set.

Parameters

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation data
        data:Add("item1", "a")
        data:Add("item2", "b")
        data:Add("item3", "c")
        data:SetKey("detail")

        JavaScriptObjectNotation json
        json:Add("data1", "A")
        json:Add("data2", "B")
        json:Add(data)

        output json:ToText()
   end
end

Add(text key, text value)

Use this method to add a text item to a JavaScriptObjectNotation object.

Parameters

  • text key: The key value to add.
  • text value: The text value to add.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", "First Name")
        json:Add("item2", "Last Name")
        output json:ToText()
   end
end

Add(text key, integer value)

Use this method to add an integer item to a JavaScriptObjectNotation object.

Parameters

  • text key: The key value to add.
  • integer value: The integer value to add.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", 1)
        json:Add("item2", 2)
        output json:ToText()
   end
end

Add(boolean value)

Use this method to add a boolean item to a JavaScriptObjectNotation array object.

Parameters

  • boolean value: The boolean value to add.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:SetKey("myArray")
        json:SetArray()
        json:Add(true)
        json:Add(true)
        json:Add(false)
        output json:ToText()
   end
end

Add(text key, boolean value)

Use this method to add a boolean item to a JavaScriptObjectNotation object.

Parameters

  • text key: The key value to add.
  • boolean value: The boolean value to add.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", true)
        json:Add("item2", false)
        output json:ToText()
   end
end

Add(number value)

Use this method to add a number item to a JavaScriptObjectNotation array object.

Parameters

  • number value: The number value to add.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:SetKey("myArray")
        json:SetArray()
        json:Add(1.1)
        json:Add(2.1)
        json:Add(3.1)
        output json:ToText()
   end
end

Add(text key, number value)

Use this method to add a number item to a JavaScriptObjectNotation object.

Parameters

  • text key: The key value to add.
  • number value: The number value to add.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", 1.1)
        json:Add("item2", 2.2)
        output json:ToText()
   end
end

Add(integer value)

Use this method to add a integer item to a JavaScriptObjectNotation array object.

Parameters

  • integer value: The integer value to add.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:SetKey("myArray")
        json:SetArray()
        json:Add(1)
        json:Add(2)
        json:Add(3)
        output json:ToText()
   end
end

Add(text key, Libraries.Data.Formats.JavaScriptObjectNotation object)

Use this method to add a nested JavaScriptObjectNotation object with a key. If the object you pass as a parameter already has a key, it will be nested inside the new key.

Parameters

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation data
        data:Add("item1", "a")
        data:Add("item2", "b")
        data:Add("item3", "c")

        JavaScriptObjectNotation json
        json:Add("data1", "A")
        json:Add("data2", "B")
        json:Add("detail", data)

        output json:ToText()
   end
end

Add(text value)

Use this method to add a text item to a JavaScriptObjectNotation array object.

Parameters

  • text value: The text value to add.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:SetKey("myArray")
        json:SetArray()
        json:Add("one")
        json:Add("two")
        json:Add("three")
        output json:ToText()
   end
end

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

Get(integer index)

Use this method to return one of the items in the json object by it's index number

Parameters

  • integer index: The index value of the JavaScriptObjectNotation object.

Return

Libraries.Data.Formats.JavaScriptObjectNotation: The JavaScriptObjectNotation object at the specified index.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", true)
        json:Add("item2", 5)

        JavaScriptObjectNotation item = json:Get(0)
        if item:GetBoolean() = true
            output "Item 1 was true"
        else
            output "Item 1 was false"
        end
   end
end

GetArray()

This action returns the array from an array object. If this object is not an array object, this throws an error.

Return

Libraries.Data.Formats.JavaScriptObjectNotation: an array object. This throws an error if this is not an array object.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
    action Main
        JavaScriptObjectNotation json
        json:SetObject()
        json:SetKey("Item")
    
        JavaScriptObjectNotation array
        array:SetArray()
        array:Add(1)
        array:Add(2)
    
        json:Add(array)
        json:SetArrayObject(true)

        //in this case, val = array
        JavaScriptObjectNotation val = json:GetArray()
        output val:ToText()
    end
end

GetBoolean(text key)

This method returns the value of a JavaScriptObjectNotation object by the key name as a JavaScriptObjectNotation object.

Parameters

  • text key

Return

boolean: The value of the object as text.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
    action Main
        JavaScriptObjectNotation json
        json:Add("key1", 1)
        json:Add("key2", 2.2)
        json:Add("key3", "three")
        json:Add("key4", true)
        JavaScriptObjectNotation nested
        nested:SetKey("key5")
        nested:Add("item1", 1)
        nested:Add("item2", 2)
        nested:Add("item3", 3)
        json:Add(nested)

        output json:GetBoolean("key4")
    end
end

GetBoolean()

Use this method to get the boolean value of a JavaScriptObjectNotation object

Return

boolean: The boolean value of the object if applicable.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", true)

        JavaScriptObjectNotation item = json:Get(0)
        output item:GetBoolean()
   end
end

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetInteger()

This method returns an integer value of a JavaScriptObjectNotation object containing an integer type

Return

integer: The integer value of the object if applicable.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", 1)
        json:Add("item2", 2)
        json:Add("item3", 3)

        sum = 0
        i = 0
        repeat json:GetSize() times
            sum = sum + json:Get(i):GetInteger()
            i = i + 1
        end
        output sum
   end
end

GetInteger(text key)

This method returns the value of a JavaScriptObjectNotation object by the key name as a JavaScriptObjectNotation object.

Parameters

  • text key

Return

integer: The value of the object as text.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
    action Main
        JavaScriptObjectNotation json
        json:Add("key1", 1)
        json:Add("key2", 2.2)
        json:Add("key3", "three")
        json:Add("key4", true)
        JavaScriptObjectNotation nested
        nested:SetKey("key5")
        nested:Add("item1", 1)
        nested:Add("item2", 2)
        nested:Add("item3", 3)
        json:Add(nested)

        output json:GetInteger("key1")
    end
end

GetIterator()

Return

Libraries.Containers.Iterator: An iterator of the JavaScriptObjectNotation objects in the object.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation
use Libraries.Containers.Iterator

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", 1.1)
        json:Add("item2", 2.2)
        json:Add("item3", 3.3)

        number sum = 0
        i = 0
        Iterator<JavaScriptObjectNotation> myIterator = json:GetIterator()

        repeat while myIterator:HasNext()
            JavaScriptObjectNotation nextItem = myIterator:Next()
            sum = sum + nextItem:GetNumber()
            i = i + 1
        end
        output sum
   end
end

GetKey()

Use this method to get the key (or name) of a JavaScriptObjectNotation object

Return

text: The name of the JavaScriptObjectNotation object.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", true)

        JavaScriptObjectNotation item = json:Get(0)
        output item:GetKey()
   end
end

GetKeys()

This method returns an array of the key names inside a JavaScriptObjectNotation object

Return

Libraries.Containers.Array: An array of key values in the object.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation
use Libraries.Containers.Array

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", 1)
        json:Add("item2", 2)
        json:Add("item3", 3)

        Array<text> keys = json:GetKeys()
        i = 0
        repeat keys:GetSize() times
            key = keys:Get(i)
            output key + " => " + json:GetValue(key)
            i = i + 1
        end
   end
end

GetNumber(text key)

This method returns the value of a JavaScriptObjectNotation object by the key name as a JavaScriptObjectNotation object.

Parameters

  • text key

Return

number: The value of the object as text.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
    action Main
        JavaScriptObjectNotation json
        json:Add("key1", 1)
        json:Add("key2", 2.2)
        json:Add("key3", "three")
        json:Add("key4", true)
        JavaScriptObjectNotation nested
        nested:SetKey("key5")
        nested:Add("item1", 1)
        nested:Add("item2", 2)
        nested:Add("item3", 3)
        json:Add(nested)

        output json:GetNumber("key2")
    end
end

GetNumber()

This method returns a number value of a JavaScriptObjectNotation object containing a number type

Return

number: The number value of the object if applicable.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", 1.1)
        json:Add("item2", 2.2)
        json:Add("item3", 3.3)

        number sum = 0
        i = 0
        repeat json:GetSize() times
            sum = sum + json:Get(i):GetNumber()
            i = i + 1
        end
        output sum
   end
end

GetObject(text key)

This method returns the value of a JavaScriptObjectNotation object by the key name as a JavaScriptObjectNotation object.

Parameters

  • text key

Return

Libraries.Data.Formats.JavaScriptObjectNotation: The value of the object as text.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
    action Main
        JavaScriptObjectNotation json
        json:Add("key1", 1)
        json:Add("key2", 2.2)
        json:Add("key3", "three")
        json:Add("key4", true)
        JavaScriptObjectNotation nested
        nested:SetKey("key5")
        nested:Add("item1", 1)
        nested:Add("item2", 2)
        nested:Add("item3", 3)
        json:Add(nested)

        output json:GetObject("key5"):GetInteger("item1")
    end
end

GetSize()

This method returns a number of children in a JavaScriptObjectNotation object.

Return

integer: The number of children in the object.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", 1.1)
        json:Add("item2", 2.2)
        json:Add("item3", 3.3)

        output json:GetSize()
   end
end

GetText()

This method returns a text value of a JavaScriptObjectNotation object containing a text type

Return

text: The text value of the object if applicable.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", "one")
        json:Add("item2", "two")
        json:Add("item3", "three")

        i = 0
        repeat json:GetSize() times
            output json:Get(i):GetText()
            i = i + 1
        end
   end
end

GetType()

This method returns a type of a JavaScriptObjectNotation object as an integer code according to the following table: INTEGER = 1 NUMBER = 2 TEXT = 3 BOOLEAN = 4 UNDEFINED = 5 ARRAY = 6 OBJECT = 7 PARENT = 8

Return

integer: The type of the object as an integer.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", "one")
        json:Add("item2", 1)
        json:Add("item3", 1.1)
        json:Add("item4", true)

        i = 0
        repeat json:GetSize() times
            output json:Get(i):GetType()
            i = i + 1
        end
   end
end

GetTypeAsText()

This method returns a type of a JavaScriptObjectNotation object as text

Return

text: The type of the object as text.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", "one")
        json:Add("item2", 1)
        json:Add("item3", 1.1)
        json:Add("item4", true)

        i = 0
        repeat json:GetSize() times
            output json:Get(i):GetTypeAsText()
            i = i + 1
        end
   end
end

GetValue(text key)

This method returns the value of a JavaScriptObjectNotation object by the key name in text format

Parameters

  • text key: The key of the object to return

Return

text: The value of the object with the specified key.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", 1)
        json:Add("item2", 2.2)
        json:Add("item3", "three")

        output json:GetValue("item1")
        output json:GetValue("item2")
        output json:GetValue("item3")
   end
end

GetValue()

This method returns the value of a JavaScriptObjectNotation object by the key name in text format

Return

text: The value of the object as text.

Example

use Libraries.Data.Formats.JavaScriptObjectNotation

class Main
   action Main
        JavaScriptObjectNotation json
        json:Add("item1", 1)
        json:Add("item2", 2.2)
        json:Add("item3", "three")

        output json:GetValue("item1")
        output json:GetValue("item2")
        output json:GetValue("item3")
   end
end

HasValue(text key)

This method returns whether or not there is an attribute at that key.

Parameters

  • tex