Platforms to show: All Mac Windows Linux Cross-Platform

Back to JSONMBS class.

JSONMBS.ApplyMergePatch(target as JSONMBS, patch as JSONMBS) as JSONMBS   New in 24.0

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 24.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Applies a merge patch to a json document.
Example
Dim source As New JSONMBS("{"+_
" ""title"": ""Goodbye!"","+_
" ""author"" : {"+_
" ""givenName"" : ""John"","+_
" ""familyName"" : ""Doe"""+_
" },"+_
" ""tags"":[ ""example"", ""sample"" ],"+_
" ""content"": ""This will be unchanged"""+_
"}")

Dim patch As New JSONMBS("{"+_
" ""title"": ""Hello!"","+_
" ""phoneNumber"": ""+01-123-456-7890"","+_
" ""author"": {"+_
" ""familyName"": null"+_
" },"+_
" ""tags"": [ ""example"" ]"+_
"}")

Dim result As JSONMBS = JSONMBS.ApplyMergePatch(source, patch)

Dim sourceText As String = source.toString(True)
Dim resultText As String = result.toString(True)
Dim PatchText As String = Patch.toString(True)

Break

The mergepatch function implement the IETF standard JSON Merge Patch

JSONMBS.ApplyPatch(target as JSONMBS, patch as JSONMBS) as JSONMBS   New in 24.0

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 24.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Applies a patch to a json document.
Example
Dim source As New JSONMBS("{""foo"": ""bar""}")
Dim patch As New JSONMBS("["+_
"{ ""op"": ""add"", ""path"": ""/baz"", ""value"": ""qux"" },"+_
"{ ""op"": ""add"", ""path"": ""/foo"", ""value"": [ ""bar"", ""baz"" ] }"+_
"]")

Dim result As JSONMBS = JSONMBS.ApplyPatch(source, patch)

Dim sourceText As String = source.toString(True)
Dim resultText As String = result.toString(True)
Dim PatchText As String = Patch.toString(True)

Break

The jsonpatch functions implement the IETF standard JavaScript Object Notation (JSON) Patch.

The JSON Patch IETF standard requires that the JSON Patch method is atomic, so that if any JSON Patch operation results in an error, the target document is unchanged. The patch function implements this requirement by generating the inverse commands and building an undo stack, which is executed if any part of the patch fails.

JSONMBS.Convert(value as variant) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 19.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Converts Xojo variant to JSON object.
Example
Dim d As New Dictionary
dim n as Double = 1/3

d.Value("number") = n // default double handling

// custom formatted number
Dim j As JSONMBS = JSONMBS.NewNumberNode(Str(n, "-0.0000000000"))

d.value("customNumber") = j
d.Value( "int64") = 1000000000000000000
d.Value("uint64") = 8000000000000000000

Dim a() As String
a.Append "Hello"
a.Append "World"

d.Value("array") = a
d.Value("dictionary") = New Dictionary("a":1, "b":2, "c":3)

Dim r As JSONMBS = JSONMBS.Convert(d)
MsgBox r.toString

Converts values in variant to matching JSON structures.
Currency is converted to double. Color is converted to integer. Dates are converted to string.
We detect arrays of String, Object, Variant, Single, Double, Int32, Int64, Boolean and Currency and convert them to JSON arrays. Dictionaries are converted to JSON objects with texts for keys.
Anything else can raise an exception about an unsupported type.

Please note that Xojo variants don't make a difference between signed and unsigned integers, so we always convert using signed integers.

With version 19.3, the array/dictionary can also contain JSONMBS objects.

See also:

JSONMBS.Flatten(value as JSONMBS) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 23.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Flattens a json object or array to a single depth object of key-value pairs.
Example
Dim j As New JSONMBS

j.Value("Hello") = "World"
j.Value("test") = 123

Dim f As JSONMBS = JSONMBS.Flatten(j)
Dim s As String = f.toString

MessageBox s
// shows: {"$['Hello']":"World","$['test']":123}

The keys in the flattened object are normalized json paths. The values are primitive (string, number, boolean, or null), empty object ({}) or empty array ([]).

JSONMBS.JSONObjectCount as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 15.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
For debugging, the plugin counts how many JSONMBS objects we have.

JSONMBS.MergePatchFromDiff(source as JSONMBS, target as JSONMBS) as JSONMBS   New in 24.0

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 24.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Create a JSON Merge Patch from a diff of two json documents.
Example
Dim source As New JSONMBS("{"+_
" ""title"": ""Goodbye!"","+_
" ""author"" : {"+_
" ""givenName"" : ""John"","+_
" ""familyName"" : ""Doe"""+_
" },"+_
" ""tags"":[ ""example"", ""sample"" ],"+_
" ""content"": ""This will be unchanged"""+_
"}")

Dim target As New JSONMBS("{"+_
" ""title"": ""Hello!"","+_
" ""author"": {"+_
" ""givenName"": ""John"""+_
" },"+_
" ""tags"": ["+_
" ""example"""+_
" ],"+_
" ""content"": ""This will be unchanged"","+_
" ""phoneNumber"": ""\u002B01-123-456-7890"""+_
"}")

Dim patch As JSONMBS = JSONMBS.MergePatchFromDiff(source, target)

Dim sourceText As String = source.toString(True)
Dim targetText As String = target.toString(True)
Dim PatchText As String = Patch.toString(True)

Break

The mergepatch function implement the IETF standard JSON Merge Patch
Returns a JSON Merge Patch.

JSONMBS.NewArrayNode as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 13.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new node for an array.
Example
dim n as JSONMBS = JSONMBS.NewArrayNode
MsgBox str(n.Type)+" = "+str(n.kTypeArray)

Some examples using this method:

JSONMBS.NewBooleanNode(value as Boolean) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 23.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a json array object with the given values.

This is a convenience method to quickly create an array.

JSONMBS.NewBoolNode(value as boolean) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 13.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new boolean node.
Example
dim j as JSONMBS = JSONMBS.NewBoolNode(true)
MsgBox j.toString

Some examples using this method:

JSONMBS.NewByteStringNode(Bytes as MemoryBlock) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 23.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new node for a byte string.
Example
Dim m As MemoryBlock = "Hello World"
Dim j As JSONMBS = JSONMBS.NewByteStringNode(m)

MessageBox j.toString
// "SGVsbG8gV29ybGQ"

Creates a new JSONMBS object with type = kTypeByteString.

See also:

JSONMBS.NewByteStringNode(Bytes as ptr, Length as UInt64) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 23.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new node for a byte string.
Example
Dim m As MemoryBlock = "Hello World"
Dim p As ptr = m
dim size as integer = m.size
Dim j As JSONMBS = JSONMBS.NewByteStringNode(p,size)

MessageBox j.toString
// "SGVsbG8gV29ybGQ"

Creates a new JSONMBS object with type = kTypeByteString.

See also:

JSONMBS.NewByteStringNode(Bytes as String) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 23.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new node for a byte string.
Example
Dim j As JSONMBS = JSONMBS.NewByteStringNode("Hello World")

MessageBox j.toString
// "SGVsbG8gV29ybGQ"

Creates a new JSONMBS object with type = kTypeByteString.

See also:

JSONMBS.NewCurrencyNode(value as Currency) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 23.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new currency value node.
Example
Dim c As Currency = 152.5678

Dim j As JSONMBS = JSONMBS.NewCurrencyNode(c)

MessageBox j.toString

Internally we store number as string with a tag marking it as big decimal, so we output it as number. If you ask for double value, we convert it of course.

JSONMBS.NewDoubleArray(values() as Double) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 13.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a json array object with the given values.
Example
dim n() as Double = array(1.0,2,3)
dim j as JSONMBS = JSONMBS.NewDoubleArray(n)
MsgBox j.toString

This is a convenience method to quickly create an array.

Version 17.0 and newer return empty JSON array node in case of empty string array.
Older versions returned nil.

JSONMBS.NewFalseNode as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 13.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new false node.
Example
dim n as JSONMBS = JSONMBS.NewFalseNode
MsgBox str(n.Type)+" = "+str(n.kTypeFalse)

This is a node which represents a boolean false value.

Some examples using this method:

JSONMBS.NewInt32Array(values() as Int32) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 23.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a json array object with the given values.

This is a convenience method to quickly create an array.

JSONMBS.NewInt64Array(values() as Int64) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 23.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a json array object with the given values.

This is a convenience method to quickly create an array.

JSONMBS.NewInt64Node(value as Int64) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 17.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new node based on Int64 value.
Example
dim x as int64 = 92233720368547758
dim n as JSONMBS = JSONMBS.NewInt64Node(x)

MsgBox "String: "+n.ValueString+EndOfLine+"ToString: "+n.toString+EndOfLine+"Double: "+str(n.ValueDouble,"-0")+EndOfLine+"Int64: "+str(n.ValueInteger,"-0")

Some examples using this method:

JSONMBS.NewIntegerArray(values() as Integer) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 13.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a json array object with the given values.
Example
dim n() as Integer = array(1,2,3)
dim j as JSONMBS = JSONMBS.NewIntegerArray(n)
MsgBox j.toString

This is a convenience method to quickly create an array.

Version 17.0 and newer return empty JSON array node in case of empty string array.
Older versions returned nil.

JSONMBS.NewNullNode as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 13.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new null node.
Example
dim n as JSONMBS = JSONMBS.NewNullNode
MsgBox str(n.Type)+" = "+str(n.kTypeNull)

This is a node which represents a nil value.

Some examples using this method:

JSONMBS.NewNumberNode(value as Double) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 13.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new number node.
Example
dim n as JSONMBS = JSONMBS.NewNumberNode(123)
MsgBox str(n.Type)+" = "+str(n.kTypeNumber)

See also:

Some examples using this method:

JSONMBS.NewNumberNode(value as string) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 17.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new number node with given number as text.
Example
dim n as JSONMBS = JSONMBS.NewNumberNode("92233720368547758")

MsgBox "String: "+n.ValueString+EndOfLine+"ToString: "+n.toString+EndOfLine+"Double: "+str(n.ValueDouble,"-0")+EndOfLine+"Int64: "+str(n.ValueInteger,"-0")

This allows you to control formatting of large integer and floating point values.

See also:

JSONMBS.NewObjectNode as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 13.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new object node.
Example
dim n as JSONMBS = JSONMBS.NewObjectNode
MsgBox str(n.Type)+" = "+str(n.kTypeObject)

Some examples using this method:

JSONMBS.NewStringArray(values() as string) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 13.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a json array object with the given values.
Example
dim n() as string = array("Hello", "World")
dim j as JSONMBS = JSONMBS.NewStringArray(n)
MsgBox j.toString

This is a convenience method to quickly create an array.

Version 17.0 and newer return empty JSON array node in case of empty string array.
Older versions returned nil.

JSONMBS.NewStringNode(value as string) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 13.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new string node.
Example
// some string with single/double quote and EndOfLine
dim s as string = "Hello'World"+EndOfLine+"this is "" a test."

// make string node
dim j as JSONMBS = JSONMBS.NewStringNode(s)

// get as JSON
dim d as string = j.toString
// show
MsgBox d

// parse again
j = new JSONMBS(d)

MsgBox j.ValueString

Some examples using this method:

JSONMBS.NewTrueNode as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 13.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new true node.
Example
dim n as JSONMBS = JSONMBS.NewTrueNode
MsgBox str(n.Type)+" = "+str(n.kTypeTrue)

This is a node which represents a boolean true value.

Some examples using this method:

JSONMBS.NewUInt32Array(values() as UInt32) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 23.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a json array object with the given values.

This is a convenience method to quickly create an array.

JSONMBS.NewUInt64Array(values() as UInt64) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 23.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a json array object with the given values.

This is a convenience method to quickly create an array.

JSONMBS.NewUInt64Node(value as UInt64) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 18.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new node based on UInt64 value.
Example
dim x as UInt64 = 92233720368547758
dim n as JSONMBS = JSONMBS.NewUInt64Node(x)

MsgBox "String: "+n.ValueString+EndOfLine+"ToString: "+n.toString+EndOfLine+"Double: "+str(n.ValueDouble,"-0")+EndOfLine+"Int64: "+str(n.ValueInteger,"-0")

JSONMBS.PatchFromDiff(source as JSONMBS, target as JSONMBS) as JSONMBS   New in 24.0

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 24.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Create a JSON Patch from a diff of two json documents.
Example
Dim source As New JSONMBS("{""/"": 9, ""foo"": ""bar""}")
Dim target As New JSONMBS("{ ""baz"":""qux"", ""foo"": [ ""bar"", ""baz"" ]}")

Dim Patch As JSONMBS = JSONMBS.PatchFromDiff(source, target)

Dim sourceText As String = source.toString(True)
Dim targetText As String = target.toString(True)
Dim PatchText As String = Patch.toString(True)

Break

Returns a JSON Patch.

The jsonpatch functions implement the IETF standard JavaScript Object Notation (JSON) Patch.

The JSON Patch IETF standard requires that the JSON Patch method is atomic, so that if any JSON Patch operation results in an error, the target document is unchanged. The patch function implements this requirement by generating the inverse commands and building an undo stack, which is executed if any part of the patch fails.

See also:

JSONMBS.PatchFromDiff(source as JSONMBS, target as JSONMBS, KeyToCopy as String) as JSONMBS   New in 24.1

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 24.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Create a JSON Patch from a diff of two json documents.

Same as normal PatchFromDiff, but copies the given primary key field from JSON entries to the diff.

See also:

JSONMBS.Unflatten(value as JSONMBS) as JSONMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method JavaScript Object Notation MBS Util Plugin 23.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Unflattens that object back to the original json.
Example
Dim t As String = "{""$['Hello']"":""World"",""$['test']"":123}"

Dim f As New JSONMBS(t)
Dim j As JSONMBS = JSONMBS.Unflatten(f)

Dim s As String = j.toString

MessageBox s
// shows: {"Hello":"World","test":123}

The keys in the flattened object are normalized json paths. The values are primitive (string, number, boolean, or null), empty object ({}) or empty array ([]).

The items on this page are in the following plugins: MBS Util Plugin.


The biggest plugin in space...