Platforms to show: All Mac Windows Linux Cross-Platform
Back to JSONMBS class.
JSONMBS.FindValueInObjectArray(Name as String, Other as JSONMBS, StartIndex as Integer = 0) as Integer
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Returns zero based index or -1 if not found.
We look into each object in the array, check if it has a value for the given label and compare that to the one to find.
Version 20.0 or newer allows with ByContent parameter = true to find by content, so number can be found via text.
StartIndex parameter added in version 21.5: Index of first element to check. Zero if not specified.
If you like to continue searching, you can pass last result + 1.
JSONMBS.HasChild(label as string) as Boolean
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 13.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Returns true if the entry exists or false if not.
Only for objects, not arrays.
Same as HasKey and HasName methods.
JSONMBS.HasKey(Key as string) as boolean
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Returns true if the entry exists or false if not.
Only for objects, not arrays.
Same as HasChild and HasName methods.
JSONMBS.HasName(Name as string) as boolean
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Returns true if the entry exists or false if not.
Only for objects, not arrays.
Same as HasKey and HasChild methods.
Some examples using this method:
JSONMBS.Insert(index as integer, value as variant)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Variant is converted to JSONMBS if needed.
If the self is an empty object, we replace it with an empty array and insert the value.
Same as AddAt method.
JSONMBS.Iterate as JSONIteratorMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Provides JSONMBS objects for inspection.
Warning: If you iterate while the JSONMBS is changed you may skip some entries or get duplicates, so please avoid editing it while iterating.
JSONMBS.IterateEntries as JSONIteratorMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Entries are provided with JSONEntryMBS objects and include key and value.
For arrays, the key name is the index value.
Warning: If you iterate while the JSONMBS is changed you may skip some entries or get duplicates, so please avoid editing it while iterating.
JSONMBS.IterateValues as JSONIteratorMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
The values are provided and converted to variant.
Warning: If you iterate while the JSONMBS is changed you may skip some entries or get duplicates, so please avoid editing it while iterating.
JSONMBS.KeyAt(index As Integer) as String
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Raises an exception if index is out of range.
Same as Name or NameAt methods.
The order of keys can change if you add/remove values in the JSON object.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
The order is as stored in memory currently and that order changes if you edit the JSON object.
We cache the array so multiple calls would return the same array and you should not modify it.
Same as Names method.
JSONMBS.Load(JSONString as String)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Text should be UTF-8.
Raises an exception in case of error.
JSONMBS.Lookup(Key As String, defaultValue As Variant = nil) as Variant
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Variant is converted to JSONMBS if needed.
Returns default value if key is not found.
JSONMBS.Merge(Other as JSONMBS)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 24.2 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
For arrays, we check if the value is already there and if not, we add it.
For objects, we check the values for each key. If it doesn't exist, we copy it over. If it exists, we check arrays and objects again, but other values just get replaced.
Raises exception if you try to merge object with array.
JSONMBS.Name(index As Integer) as String
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Raises an exception if index is out of range.
Same as NameAt or KeyAt methods.
See also:
JSONMBS.NameAt(index As Integer) as String
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Raises an exception if index is out of range.
Same as Name or KeyAt methods.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
The order is as stored in memory currently and that order changes if you edit the JSON object.
We cache the array so multiple calls would return the same array and you should not modify it.
Same as Keys method.
JSONMBS.Operator_Compare(Other as JSONMBS) as Integer
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Called automatically by Xojo if you use =, > and < operators.
Same as Compare method.
JSONMBS.Operator_Convert as Variant()
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Convenience function to get all values.
Converts values to variants as needed.
Works for both objects and arrays.
Same as Values method.
See also:
JSONMBS.Operator_Convert(dic As Dictionary)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Converts all dictionary values to JSON objects internally.
See also:
JSONMBS.Operator_Subscript(index As Integer) as Variant
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
property | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Variant is converted to JSONMBS if needed.
Index must be in range from 0 to Count. If index is equal to count, we append the value on setting.
If the self is an empty object, we replace it with an empty array and add the value.
Same as ValueAt or Operator_Subscript.
(Read and Write computed property)
Some examples using this property:
JSONMBS.Query(Path as string, Options as Integer = 0) as JSONMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Evaluates the root value against the JSONPath expression and returns an array of values or normalized path expressions.
Returns a JSON with an array containing either values or normalized path expressions matching the JSONPath expression, or an empty array if there is no match.
For options use kPathResultOptions* constants. Use OR to combine multiple flags.
kPathResultOptionsValue | Return values. |
kPathResultOptionsNoDuplicates | Remove duplicates. |
kPathResultOptionsSort | Sort results. |
kPathResultOptionsPath | Return paths. |
To learn more about JSONPath, please check this website:
https://goessner.net/articles/JsonPath/
Learn more about the JSONPath implementation here:
https://danielaparker.github.io/JsonCons.Net/articles/JsonPath/JsonConsJsonPath.html
See also Replace() to replace found values with new values.
JSONMBS.Remove(Index as Integer)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Works for arrays or objects.
For objects, prefer to delete by key name since removing an entry changes the order.
Same as RemoveAt method.
See also:
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Only for JSONMBS of type object.
See also:
JSONMBS.RemoveAt(Index as Integer)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Works for arrays or objects.
For objects, prefer to delete by key name since removing an entry changes the order.
Same as Remove method.
JSONMBS.Replace(Path as string, NewValue as Variant) as JSONMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | JavaScript Object Notation | MBS Util Plugin | 23.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Throws a JSONExceptionMBS if JSONPath evaluation fails.
Returns the modified copy of the JSON.
See also Query() function to just search without replace.
The items on this page are in the following plugins: MBS Util Plugin.