Platforms to show: All Mac Windows Linux Cross-Platform

JSONMBS class

Type Topic Plugin Version macOS Windows Linux iOS Targets
class JavaScript Object Notation MBS Util Plugin 13.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Function: The class for JSON object parsing and creating.
Example:
dim o as JSONMBS = JSONMBS.NewObjectNode

o.AddItemToObject "Hello", JSONMBS.NewNumberNode(1)
o.AddItemToObject "World", JSONMBS.NewNumberNode(2)

MsgBox o.toString
Notes:
Our JSON class
  • has a high performance.
  • is based on a modern C++ library
  • supports Xojo features like for-each loops with iterators
  • is almost compatible to the old JSONMBS class from before
  • is almost compatible to JSONItem class
  • automatically converts between variant and JSONMBS as needed.
  • reports errors with JSONException class.
  • can query, search and replace JSON values with JSON Paths.
  • can flatten and unflatten JSON.
  • can create patches and merge them back with two ways.
  • provides a lot of convenience functions.
  • can convert from JSON to/from dictionaries and arrays.
  • handles currency better and preserves digits.
  • has a lot of duplicate method/property names for API 1 and 2 compatibility and you can choose whether you prefer Append vs Add, Insert vs. AddAt or Key vs. NameAt.
  • preserves the order of object entries and allows explicit sorting.
  • can convert to HTML for displaying itself.
  • prefers case sensitive, but can optionally do case insensitive.
We can convert integer, boolean, string, double, arrays, dictionaries to JSON internally.
And convert back to variant containing integer, boolean, string, double, arrays and dictionaries.

We back ported things like GetChildNode, GetNextNode and GetPreviousNode, but those are not very efficient and you may want to move to using iterators, query values/entries/keys arrays or access items by index.

The old class is still available in a separated OldJSON Plugin for our customers for compatibility with class renamed to OldJSONMBS.
  • 37 properties
  • shared property CaseSensitive as Boolean   New in 23.5
  • 51 methods
    • method Add(Value as Variant)   New in 23.5
    • method AddAt(index As Integer, value As Variant)   New in 23.5
    • method AddItemToArray(item as JSONMBS)
    • method AddItemToObject(label as string, value as JSONMBS)
    • method AddOrReplaceItemToObject(label as string, value as JSONMBS)
    • method Append(Value as Variant)   New in 23.5
    • method ArrayItem(index as integer, Clone as Boolean = false) as JSONMBS
    • method ArrayItems(Clone as Boolean = false) as JSONMBS()
    • method Clear   New in 23.5
    • method Clone as JSONMBS
    • method Close
    • method Compare(Other as JSONMBS) as Integer   New in 23.5
    • method Constructor
    • method Constructor(dic As Dictionary)   New in 23.5
    • method Constructor(JSONString as String)   New in 23.5
    • method Constructor(other as JSONMBS)   New in 23.5
    • method Convert as Variant
    • method DeleteItem(index as Integer)
    • method DeleteItem(label as string)
    • method Entries as JSONEntryMBS()   New in 23.5
    • method Equals(Other as JSONMBS) as Boolean
    • method FilterObjectArray(Name as String, Other as JSONMBS) as JSONMBS   New in 23.5
    • method FindValueInArray(Other as JSONMBS, StartIndex as Integer = 0) as Integer   New in 23.5
    • method FindValueInObjectArray(Name as String, Other as JSONMBS, StartIndex as Integer = 0) as Integer   New in 23.5
    • method HasChild(label as string) as Boolean
    • method HasKey(Key as string) as boolean   New in 23.5
    • method HasName(Name as string) as boolean   New in 23.5
    • method Insert(index as integer, value as variant)   New in 23.5
    • method Iterate as JSONIteratorMBS   New in 23.5
    • method IterateEntries as JSONIteratorMBS   New in 23.5
    • method IterateValues as JSONIteratorMBS   New in 23.5
    • method KeyAt(index As Integer) as String   New in 23.5
    • method Keys as String()   New in 23.5
    • method Load(JSONString as String)   New in 23.5
    • method Lookup(Key As String, defaultValue As Variant = nil) as Variant   New in 23.5
    • method Name(index As Integer) as String   New in 23.5
    • method NameAt(index As Integer) as String   New in 23.5
    • method Names as String()   New in 23.5
    • method Operator_Compare(Other as JSONMBS) as Integer   New in 23.5
    • method Operator_Convert as Variant()   New in 23.5
    • method Operator_Convert(dic As Dictionary)   New in 23.5
    • method Query(Path as string, Options as Integer = 0) as JSONMBS   New in 23.5
    • method Remove(Index as Integer)   New in 23.5
    • method Remove(Key as string)   New in 23.5
    • method RemoveAt(Index as Integer)   New in 23.5
    • method Replace(Path as string, NewValue as Variant) as JSONMBS   New in 23.5
    • method Search(Path as string) as JSONMBS   New in 23.5
    • method Sort(Reverse as boolean = false)   New in 23.5
    • method ToHTML(NoHeader as boolean = false, CSS as string = "") as String
    • method toString(formatted as boolean) as string
    • method Values as Variant()   New in 23.5
  • 24 shared methods
  • 35 constants

Query Result Options

Constant Value Description
kPathResultOptionsNoDuplicates 1 Remove duplicates.
kPathResultOptionsPath 4 Return paths.
kPathResultOptionsSort 2 Sort results.
kPathResultOptionsValue 0 Return value.

Tags

Constant Value Description
kTagBase16 &h1a Base16 (Hex)
kTagBase64 &h1b base64
kTagBase64url &h1c base64 URL
kTagBigDec 7 Big decimal
kTagBigFloat 8 Big Float
kTagBigInt 6 Big Integer
kTagClamped &h0e clamped
kTagCode &h14 code
kTagDateTime 2 DateTime
kTagEpochMilli 4 epoch-milli
kTagEpochNano 5 epoch-nano
kTagEpochSecond 3 epoch-second
kTagExt &h11 ext
kTagFloat128 9 Float 128 bit
kTagId &h12 id
kTagMultiDimColumnMajor &h10 multi-dim-column-major
kTagMultiDimRowMajor &h0f multi-dim-row-major
kTagNone 0 n/a
kTagRegex &h13 regex
kTagUndefined 1 undefined
kTagURI &h0d URI

Types

Constant Value Description
kTypeArray 8 For an array node.
kTypeBoolean 1 For a boolean node.
kTypeByteString 7 For a byte string node.
Currently only used for MemoryBlocks passed via Variant.
kTypeDouble 5 For a double node.
kTypeInt64 2 For a Int64 node.
kTypeNull 0 For a null node.
kTypeObject 9 For a object node.
kTypeSingle 4 For a single node.
kTypeString 6 For a string node. Also applies to big numbers.
kTypeUInt64 3 For an uint64 node.

This class has no sub classes.

Some properties using for this class:

Some examples using this class:

Blog Entries

Xojo Developer Magazine

Videos


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


JSONIteratorMBS   -   JSValueMBS


💬 Ask a question or report a problem
The biggest plugin in space...