Libraries.Data.Formats.JavaScriptObjectNotationReader Documentation

This class can read in JavaScriptObjectNotation (JSON) formatted data from text values or from disk. When it reads them in, the object is parsed and placed into a set of objects. 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
use Libraries.Data.Formats.JavaScriptObjectNotationReader
class Main
   action Main
      text dq = ""
        dq = dq:GetDoubleQuote()
        JavaScriptObjectNotationReader reader
        text myValue = "{" + dq + "data" + dq + ": [21.5, 22.7, 23.9]}"
        JavaScriptObjectNotation json = reader:ReadToObject(myValue)
        i = 0
        repeat while i < object:GetSize()
            JavaScriptObjectNotation next = json:Get(i)
            if next:GetKey() = "data"
                output "data"
                JavaScriptObjectNotation array = next:Get(0)
                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

Summary

Actions Summary Table

ActionsDescription
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetHashCode()This action gets the hash code for an object.
GetListener()This action retrieves a listener, if one was set, that receives events related to parsing the JavaScriptObjectNotation (JSON) text.
Read(Libraries.System.File file)This action reads a file from disk and asks the JavaScriptObjectNotation system to read it in.
Read(text value)This action reads a file from disk and asks the JavaScriptObjectNotation system to read it in.
ReadToObject(text value)This action can read in JavaScriptObjectNotation (JSON) files from text values.
ReadToObject(Libraries.System.File file)This action can read in JavaScriptObjectNotation (JSON) files from text values.
SetListener(Libraries.Data.Formats.JavaScriptObjectNotationListener listener)This action sets a listener, if one was set, that receives events related to parsing the JavaScriptObjectNotation (JSON) text.

Actions Documentation

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.

Example Code

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

Parameters

Return

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

Equals(Libraries.Language.Object object)

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

Example Code

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

Parameters

Return

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

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

GetListener()

This action retrieves a listener, if one was set, that receives events related to parsing the JavaScriptObjectNotation (JSON) text.

Return

Libraries.Data.Formats.JavaScriptObjectNotationListener:

Read(Libraries.System.File file)

This action reads a file from disk and asks the JavaScriptObjectNotation system to read it in. Unlike ReadToObject(File file), which reads the file to an object representing the original source, this action is designed to allow the programmer to manually follow the parse as it proceeds. As such, to obtain any information from the system, the programmer needs to extend the JavaScriptObjectNotationListener class and use it to capture events as they are parsed. For most users, use of ReadToObject(File file) is recommended over this one.

Example Code

use Libraries.Data.Formats.JavaScriptObjectNotation
        use Libraries.Data.Formats.JavaScriptObjectNotationReader
        use Libraries.Data.Formats.JavaScriptObjectNotationListener

        class Main is JavaScriptObjectNotationListener
            action Main
                JavaScriptObjectNotationReader reader
                reader:SetListener(me)

                File file
                file:SetPath("Test.json")   
                reader:Read(file)
            end
           
            //output any values
            action VisitString(JavaScriptObjectNotationTerminal terminal)
                output token:value
            end
        end

Parameters

Read(text value)

This action reads a file from disk and asks the JavaScriptObjectNotation system to read it in. Unlike ReadToObject(File file), which reads the file to an object representing the original source, this action is designed to allow the programmer to manually follow the parse as it proceeds. As such, to obtain any information from the system, the programmer needs to extend the JavaScriptObjectNotationListener class and use it to capture events as they are parsed. For most users, use of ReadToObject(File file) is recommended over this one.

Example Code

use Libraries.Data.Formats.JavaScriptObjectNotation
        use Libraries.Data.Formats.JavaScriptObjectNotationReader
        use Libraries.Data.Formats.JavaScriptObjectNotationListener

        class Main is JavaScriptObjectNotationListener
            action Main
                JavaScriptObjectNotationReader reader
                reader:SetListener(me)

                File file
                file:SetPath("Test.json")   
                reader:Read(file:Read())
            end
           
            //output any values
            action VisitString(JavaScriptObjectNotationTerminal terminal)
                output token:value
            end
        end

Parameters

ReadToObject(text value)

This action can read in JavaScriptObjectNotation (JSON) files from text values. When it reads them in, the object is parsed and placed into a set of objects.

Example Code

use Libraries.Data.Formats.JavaScriptObjectNotation
    use Libraries.Data.Formats.JavaScriptObjectNotationReader
    class Main
       action Main
            text dq = ""
            dq = dq:GetDoubleQuote()
            JavaScriptObjectNotationReader reader
            text myValue = "{" + dq + "data" + dq + ": [21.5, 22.7, 23.9]}"
            JavaScriptObjectNotation json = reader:ReadToObject(myValue)
            i = 0
            repeat while i < json:GetSize()
                JavaScriptObjectNotation next = json:Get(i)
                if next:GetKey() = "data"
                    output "data"
                    JavaScriptObjectNotation array = next:Get(0)
                    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

Parameters

Return

Libraries.Data.Formats.JavaScriptObjectNotation:

ReadToObject(Libraries.System.File file)

This action can read in JavaScriptObjectNotation (JSON) files from text values. When it reads them in, the object is parsed and placed into a set of objects.

Example Code

use Libraries.Data.Formats.JavaScriptObjectNotation
    use Libraries.Data.Formats.JavaScriptObjectNotationReader
    class Main
       action Main
            JavaScriptObjectNotationReader reader
            
            File file
            file:SetPath("Test.json")
            JavaScriptObjectNotation json = reader:ReadToObject(file)
            i = 0
            repeat while i < json:GetSize()
                JavaScriptObjectNotation next = json:Get(i)
                if next:GetKey() = "data"
                    output "data"
                    JavaScriptObjectNotation array = next:Get(0)
                    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

Parameters

Return

Libraries.Data.Formats.JavaScriptObjectNotation:

SetListener(Libraries.Data.Formats.JavaScriptObjectNotationListener listener)

This action sets a listener, if one was set, that receives events related to parsing the JavaScriptObjectNotation (JSON) text.

Parameters