JSON Parser Xojo plugin

EinhugurJSON.JSONObject Class (console safe)

A JSON object is a dictionary of key-value pairs, where the key is a Unicode string and the value is any JSON value.

Even though null bytes are allowed in string values, they are not allowed in object keys.

JSONPrimitive
   JSONObject

class EinhugurJSON.JSONObject

Constructors

JSONObjectConstructor that takes no parameters.

Properties

BooleanValue (Inherited) Returns the value as Boolean from the primitive
CountReturns the number of elements in the object.
DoubleValue (Inherited) Returns the value as Double from the primitive
IntegerValue (Inherited) Returns the value as Integer (Int64) from the primitive
IsArray (Inherited) Returns true if the primitive contains Array.
IsBoolean (Inherited) Returns true if the primitive contains Boolean.
IsDouble (Inherited) Returns true if the primitive contains Double.
IsFalse (Inherited) Returns true if the primitive is false.
IsInteger (Inherited) Returns true if the primitive contains Integer value.
IsNull (Inherited) Returns true if the primitive contains null or nil.
IsNumber (Inherited) Returns true if the primitive contains number (can be Integer or Double)
IsObject (Inherited) Returns true if the primitive contains JSONObject (dictionary)
IsString (Inherited) Returns true if the primitive contains String.
IsTrue (Inherited) Returns true if the primitive is true.
NumberValue (Inherited) Returns the value as Double from the primitive, reading the value either from Integer or Double, not caring which one it is.
StringValue (Inherited) Returns the value as String from the primitive
Type (Inherited) Returns type code for the primitive. The type code can be any value from the JSONPrimitive.NodeTypeEnum.

Methods

BooleanValueByKeyReads or writes Boolean value in the array by key.
ClearClears all elements from the JSONObject.
Clone (Inherited) Makes a clone of the JSONPrimitive.
ContainsKeyReturns true if the JSON object contains the given key.
CreateIteratorCreates iterator to iterate through the JSONObject.
CreateIteratorCreates iterator to iterate through the JSONObject. This variation will start the iterator at given key.
DoubleValueByKeyReads or writes Double value in the array by key.
GetSource (Inherited) Generates JSON string from the JSON object model. All parameters of this function are optional.
IntegerValueByKeyReads or writes Integer value in the array by key.
Operator_Compare (Inherited) Comparison operator to compare two JSONPrimitives with the standard Xojo = operator.
Operator_SubscriptReads value from the JSONObject by key using standard array operator.
Operator_SubscriptWrites value to the JSONObject by key using standard array operator.
RemoveRemoves element by key from the JSONObject.
StringValueByKeyReads or writes String value in the array by key.
ToVariant (Inherited) Attempts to convert the JSON structure to variant. Taking optional delegate to evaluate custom structures such as color and date which are not part of normal JSON standard.
UpdateUpdates the JSONObject (Dictionary) with values from other JSONObject overriding existing keys.
UpdateExistingUpdates the JSONObject (Dictionary) with values from other JSONObject overriding existing keys, updating only keys value pairs that already exist in the current JSONobject. No new keys are created in the current JSONobject.
UpdateMissingUpdates the JSONObject (Dictionary) with values from other JSONObject only adding key value pairs which are missing in the current JSONobject. Only new keys are created and no existing keys are updated.
WalkCalls the given delegate routine for each element in the JSONObject.
WalkSafeSame as walk but deleting during walk is safe in this version. Walk is slower though.

Delegates

WalkJSONObjectDelegate (console safe) A delegate for the Walk method on this class.

Examples


using EinhugurJSON

Dim root as JSONObject = new JSONObject()
Dim arr as JSONArray = new JSONArray()

root.StringValueByKey("RootA") = "Hello world"
root("ArrayOfNumbers") = arr
arr.AppendInteger(16)
arr.AppendInteger(42)
arr.AppendInteger(128)

// Put the raw source to the edit field
TextArea1.Text = root.GetSource()
TextArea2.Text = root.GetSource(true, 0)



Parsing the same code back:

using EinhugurJSON

if TextArea1.Text = "" then
   MsgBox "There is nothing in the textbox"
else
   Dim result as JSONParseResult = JSONPrimitive.Parse(TextArea1.Text)
   
   if result.Root <> nil then
      if result.Root isa JSONObject then
         MsgBox JSONObject(result.Root).StringValueByKey("RootA")
      end if
   else
      MsgBox "Error"
   end if
end if

Supported Platforms:

  • macOS Intel 32 bit
  • macOS Intel 64 bit
  • macOS Apple Silicon
  • Windows 32 bit
  • Windows 64 bit
  • Windows ARM 64 bit
  • Linux 32 bit
  • Linux 64 bit
  • Linux ARM 32 bit
  • Linux ARM 64 bit
  • iOS