The code below has two classes, a JsonArray and a JsonObject, so we can make json objects starting from an object or an array. Parser included in both objects. Also the parser isn't recursive. The JsonObject is based on an older class named FastCollection, which use an array of a UDT and another hash array, using the HashData function of shlwapi library.
We can build a json structure, applying values, or by using a path. Also we can retrieve or update a value (and change to anoher type if we wish), using a path.
We get this. Array is zero based. So 3 in the path above is the fourth item
We can put null using k.nullvalue, or for arrays as in the example above, when we place an item above upper bound. For arrays, we can insert a number null values moving items up, and we can delete an number of items.
We can use the path to update the value using AssignPath statement, and we can use another format:
We can mix JsonObjects with JsonArrays because the basic statements are the same (like a common interface).
So we can use something like this:
I didn't use a collection, because my fastcollection uses a hash table which is fast without using the one error statement to handle the finding procedure.
We can store any numeric type (stored on a Variant array), boolean, null, and the two objects, the JsonObject and the JsonArray. Parsing handle escape characters, and the json property render the the structure to string changing the string using escaped characters. The null value is the VBEmpty.
George
- Removing the mistake "/" with the backslash "". Thanks to wqweto, who check it.
Version 3 uploaded
We can build a json structure, applying values, or by using a path. Also we can retrieve or update a value (and change to anoher type if we wish), using a path.
Code:
Dim k As New JsonObject
k.AssignPath "hello.0.one.3", 500
Debug.Print k.Json(4)
Code:
{
"hello" : [
{
"one" : [
null,
null,
null,
500
]
}
]
}
We can use the path to update the value using AssignPath statement, and we can use another format:
Code:
Dim kK as New JsonArray
kk.AssignPath "1-1-1-0", kk.anArray(0, 500), "-"
Debug.Print kk(1)(1)(1)(0)(0) ' 500
kk(1)(1)(1)(0)(0) = 8000
Debug.Print kk(1)(1)(1)(0)(0) ' 8000
So we can use something like this:
Code:
Debug.Print k("other key")(0)("one3")(1)
We can store any numeric type (stored on a Variant array), boolean, null, and the two objects, the JsonObject and the JsonArray. Parsing handle escape characters, and the json property render the the structure to string changing the string using escaped characters. The null value is the VBEmpty.
George
- Removing the mistake "/" with the backslash "". Thanks to wqweto, who check it.
Version 3 uploaded