ILV2Json Interface coclass LiteView2Json | Standalone JSON engine | No WebView2 required
LiteView2.Json is a standalone COM object — it works in any VBA host (Access, Excel, VB6) with or without WebView2. All JSON parsing is performed in native C++. No browser instance is required. Activate with CreateObject("LiteView2.Json") in both registered and registration-free modes.
Getting Started
In registered mode (after regsvr32) or registration-free mode (OCX placed next to your database), activate with a single line:
Dim j As Object
Set j = CreateObject("LiteView2.Json")
Registration-Free Setup
If using the OCX without registration (no admin rights), call LiteView2_ActivateManifest first — the same call you make for IBrowserPool. Once the manifest is active, CreateObject("LiteView2.Json") resolves automatically.
' Inside your GetPool() or init function, before CreateObject
#If Win64 Then
LiteView2_ActivateManifest StrPtr(CurrentProject.Path & "\LiteView2_x64.ocx")
#Else
LiteView2_ActivateManifest StrPtr(CurrentProject.Path & "\LiteView2_x86.ocx")
#End If
Dim j As Object
Set j = CreateObject("LiteView2.Json") ' works in both modes
Licensing
Object creation always succeeds regardless of license state. The license is checked at the first method call. During the 30-day trial, all methods are fully functional. After trial expiry, methods return E_ACCESSDENIED.
' No ActivateLicense call on the Json object itself.
' License is shared with LiteView2 — activate once via IBrowserPool or ILiteView2Ctrl:
pool.ActivateLicense "My Company", "LICENSE-KEY-HERE" ' unlocks all LiteView2 objects
Three Performance Tiers
LiteView2.Json — Three Performance Tiers
|
+-- Tier 1: Stateless
| j.GetValue(jsonString, "path")
| Simplest. Re-parses the JSON string on every call.
| Use for one-off lookups or small JSON.
|
+-- Tier 2: DOM Handle
| h = j.Parse(jsonString) ← parse once
| j.GetValueH(h, "path") ← query many times
| j.CountH(h, "items")
| j.Release(h)
| Use when querying the same JSON multiple times.
|
+-- Tier 3: Compiled Path
h = j.Parse(jsonString) ← parse once
pp = j.CompilePath("user.name") ← compile once
For i = 1 To 10000
v = j.GetValueHP(h, pp) ← zero parsing, zero allocation
Next i
j.ReleasePath pp
j.Release h
Use for hot loops or high-frequency repeated queries.
All Three Tiers — Complete Example
Dim j As Object
Set j = CreateObject("LiteView2.Json")
Dim js As String
js = "{""user"":{""name"":""Alice"",""age"":30,""active"":true}}"
' Tier 1 — stateless (re-parses each call)
Debug.Print j.GetValue(js, "user.name") ' → "Alice"
Debug.Print j.GetValue(js, "user.age") ' → 30
' Tier 2 — parse once, query many times
Dim h As Long
h = j.Parse(js)
Debug.Print j.GetValueH(h, "user.name") ' → "Alice"
Debug.Print j.GetValueH(h, "user.age") ' → 30
Debug.Print j.GetValueH(h, "user.active") ' → True
j.Release h
' Tier 3 — compiled path (zero allocation hot loop)
h = j.Parse(js)
Dim pp As Long
pp = j.CompilePath("user.name")
Dim i As Long
For i = 1 To 10000
Dim v As Variant
v = j.GetValueHP(h, pp) ' zero parsing, zero allocation
Next i
j.ReleasePath pp
j.Release h
Error Contract
| Condition | Return Value | VBA Err.Number |
|---|---|---|
| Path not found | Empty (VT_EMPTY) | 0 (no error) |
| JSON null value | Null (VT_NULL) | 0 (no error) |
| Array index out of range | Empty (VT_EMPTY) | 0 (no error) |
| Invalid JSON string | — | E_INVALIDARG — "Invalid JSON at position N" |
| Invalid handle number | — | E_HANDLE — "Invalid JSON handle: N" |
| Invalid path syntax | — | E_INVALIDARG — "Invalid path syntax at position N" |
| JSON exceeds MaxSize | — | E_FAIL — "JSON exceeds maximum size (50MB)" |
| DOM memory limit exceeded | — | E_OUTOFMEMORY — "DOM build exceeded memory limit" |
| Nesting depth > 256 | — | E_FAIL — "JSON nesting depth exceeds 256" |
| License not activated | — | E_ACCESSDENIED — "LiteView2 license required" |
Methods never raise a VBA error for "not found" — they return Empty. Use IsEmpty(j.GetValue(...)) to check for missing paths. Use IsNull(j.GetValue(...)) to detect JSON null values.
Stateless read methods — each call parses the JSON string from scratch (Tier 1). Use these for simple one-off lookups. For repeated queries on the same JSON, use the Handle Model instead.
| Member | Parameters | Returns | Description |
|---|---|---|---|
| GetValue | json As String, path As String | Variant | Return typed value at path. Empty if not found, Null if JSON null. Numeric types return Long or Double; booleans return Boolean. |
| GetItem | json As String, path As String, index As Long | String | Return the serialised JSON of the array element at path[index] (0-based). Empty string if out of range. |
| GetKeys | json As String, path As String | String | Return comma-separated list of object keys at path. Empty string if path points to a non-object. |
| Count | json As String, path As String | Long | Return number of elements (array) or members (object) at path. Returns 0 if path not found or value is scalar. |
| Exists | json As String, path As String | Boolean | Return True if the path exists in the JSON (even if the value is null). |
| IsValid | json As String | Boolean | Return True if json is syntactically valid JSON. Does not raise an error on invalid input. |
Path Syntax
Paths use dot notation for object keys and bracket notation for array indices:
' Object key navigation
j.GetValue(js, "user.address.city")
' Array index (0-based)
j.GetValue(js, "items[0].name")
j.GetValue(js, "items[2].price")
' Root value (empty path)
j.GetValue("""hello""", "") ' → "hello"
' Nested arrays
j.GetValue(js, "matrix[0][1]")
Read Examples
Dim j As Object
Set j = CreateObject("LiteView2.Json")
Dim js As String
js = "{""items"":[{""id"":1,""name"":""Widget""},{""id"":2,""name"":""Gadget""}]}"
' GetValue — typed return
Debug.Print j.GetValue(js, "items[0].id") ' → 1 (Long)
Debug.Print j.GetValue(js, "items[1].name") ' → "Gadget" (String)
Debug.Print IsEmpty(j.GetValue(js, "missing")) ' → True
' Count — array length
Debug.Print j.Count(js, "items") ' → 2
' GetKeys — object member names
Debug.Print j.GetKeys(js, "items[0]") ' → "id,name"
' Exists — presence check
Debug.Print j.Exists(js, "items[0].id") ' → True
Debug.Print j.Exists(js, "items[5]") ' → False
' IsValid — syntax check
Debug.Print j.IsValid("{""a"":1}") ' → True
Debug.Print j.IsValid("{bad json}") ' → False (no error raised)
Stateless mutation methods — each returns a new JSON string with the modification applied. The original string is never modified. Methods are chainable: pass the result of one call as input to the next.
| Member | Parameters | Returns | Description |
|---|---|---|---|
| CreateObject | String | Return an empty JSON object: {} | |
| CreateArray | String | Return an empty JSON array: [] | |
| SetValue | json As String, path As String, value As Variant | String | Set (or add) the value at path. Intermediate objects are created automatically. Accepts String, Long, Double, Boolean, or Null. |
| Remove | json As String, path As String | String | Remove the key or array element at path. No-op if path does not exist. |
| Append | json As String, path As String, value As Variant | String | Append value to the array at path. The target must be an array. |
| Insert | json As String, path As String, index As Long, value As Variant | String | Insert value into the array at path before position index (0-based). |
| Clear | json As String, path As String | String | Clear all elements from the array or object at path, leaving it empty. |
| Merge | json1 As String, json2 As String, deep As Boolean | String | Merge json2 into json1. If deep is True, nested objects are merged recursively; otherwise top-level keys from json2 overwrite json1. |
Write Examples
Dim j As Object
Set j = CreateObject("LiteView2.Json")
' Build a JSON object from scratch
Dim js As String
js = j.CreateObject() ' → {}
js = j.SetValue(js, "name", "Alice") ' → {"name":"Alice"}
js = j.SetValue(js, "age", 30) ' → {"name":"Alice","age":30}
js = j.SetValue(js, "active", True) ' → {"name":"Alice","age":30,"active":true}
' Append to array
Dim arr As String
arr = j.CreateArray() ' → []
arr = j.Append(arr, "", "first") ' → ["first"]
arr = j.Append(arr, "", "second") ' → ["first","second"]
arr = j.Insert(arr, "", 0, "zeroth") ' → ["zeroth","first","second"]
' Remove a key
js = j.Remove(js, "active") ' → {"name":"Alice","age":30}
' Deep merge
Dim merged As String
merged = j.Merge("{""a"":1,""b"":{""x"":1}}", _
"{""b"":{""y"":2},""c"":3}", True)
' → {"a":1,"b":{"x":1,"y":2},"c":3}
Structural transformation methods. All accept a JSON string and return a transformed string or SAFEARRAY.
| Member | Parameters | Returns | Description |
|---|---|---|---|
| PrettyPrint | json As String | String | Return a human-readable, indented version of json. |
| Flatten | json As String | String | Flatten a nested JSON object into dot-path keys: {"a":{"b":1}} → {"a.b":1}. |
| Unflatten | json As String | String | Reverse of Flatten — expand dot-path keys back into nested objects. |
| ToArray | json As String | Variant (1D array) | Convert a JSON array to a VBA Variant containing a 1-based String() array of serialised JSON elements. Subject to MaxSize limit. |
| ToRowArray | json As String | Variant (2D array) | Convert a JSON array-of-objects into a 2D Variant() with headers in row 0 and typed values in subsequent rows. Subject to MaxSize limit. |
| BuildJson | inputData As Variant | String | Convert a VBA value to a JSON string. Accepts String, Long, Double, Boolean, Null, or a 1D/2D SAFEARRAY of Variants. |
| UnwrapString | jsonValue As String | String | If jsonValue is a JSON string literal (double-encoded), unwrap one layer and unescape all JSON sequences (\", \\, \n, \uXXXX, etc.). Otherwise return unchanged. |
| Compact | json As String, path As String | String | Remove null entries from a JSON array at path. Pass empty string for root array. Useful for financial API data with null-padded timeseries. |
Transform Examples
Dim j As Object
Set j = CreateObject("LiteView2.Json")
' PrettyPrint
Debug.Print j.PrettyPrint("{""a"":1,""b"":[1,2]}")
' {
' "a": 1,
' "b": [
' 1,
' 2
' ]
' }
' Flatten / Unflatten
Dim flat As String
flat = j.Flatten("{""user"":{""name"":""Alice"",""age"":30}}")
' → {"user.name":"Alice","user.age":30}
Debug.Print j.Unflatten(flat)
' → {"user":{"name":"Alice","age":30}}
' ToRowArray — convert array-of-objects to 2D grid (like a recordset)
Dim js As String
js = "[{""id"":1,""name"":""Alice""},{""id"":2,""name"":""Bob""}]"
Dim grid As Variant
grid = j.ToRowArray(js)
' grid(0,0)="id" grid(0,1)="name" ← headers in row 0
' grid(1,0)=1 grid(1,1)="Alice"
' grid(2,0)=2 grid(2,1)="Bob"
' BuildJson — VBA array → JSON
Dim arr(1) As Variant
arr(0) = "hello" : arr(1) = 42
Debug.Print j.BuildJson(arr) ' → ["hello",42]
' UnwrapString — fix double-encoded JSON string from WebView2
Debug.Print j.UnwrapString("""{\""name\"":\""Apple\""}""")
' → {"name":"Apple"}
' Compact — remove null entries from JSON array
Debug.Print j.Compact("[null,{""id"":1},null,{""id"":2}]", "")
' → [{"id":1},{"id":2}]
' Path-based compact
Debug.Print j.Compact("{""data"":[null,{""v"":1},null]}", "data")
' → {"data":[{"v":1}]}
Tier 2 performance model. Parse() builds a DOM tree from the JSON string once. The returned handle can be queried many times with zero re-parsing. Always call Release() when done to free the DOM memory.
Handles are per-object — a handle from one LiteView2.Json instance cannot be used with a different instance. Always release handles you no longer need; they are not freed automatically until ReleaseAll() or object destruction.
| Member | Parameters | Returns | Description |
|---|---|---|---|
| Parse | json As String | Long | Parse json into an internal DOM tree. Returns a handle (>0) on success. Raises E_INVALIDARG on invalid JSON or E_OUTOFMEMORY if the DOM exceeds MaxSize. |
| Release | handle As Long | Free the DOM tree for handle. Safe to call multiple times on the same handle. | |
| ReleaseAll | Free all JSON handles and release all DOM memory. Use at form unload or module cleanup. | ||
| GetValueH | handle As Long, path As String | Variant | Return typed value at path from the pre-built DOM. Raises E_HANDLE on invalid handle. |
| GetItemH | handle As Long, path As String, index As Long | String | Return serialised JSON of the array element at path[index] (0-based). |
| GetKeysH | handle As Long, path As String | String | Return comma-separated keys of the object at path. |
| CountH | handle As Long, path As String | Long | Return number of elements (array) or members (object) at path. |
| ExistsH | handle As Long, path As String | Boolean | Return True if path exists in the DOM. |
Handle Model Example — Iterating an Array
Dim j As Object
Set j = CreateObject("LiteView2.Json")
Dim js As String
js = "[{""id"":1,""price"":9.99},{""id"":2,""price"":14.99},{""id"":3,""price"":4.99}]"
Dim h As Long
h = j.Parse(js) ' parse once
Dim n As Long
n = j.CountH(h, "") ' → 3 (array length at root)
Dim i As Long
For i = 0 To n - 1
Dim id As Long
Dim price As Double
id = j.GetValueH(h, "[" & i & "].id")
price = j.GetValueH(h, "[" & i & "].price")
Debug.Print "Item " & id & ": $" & price
Next i
j.Release h ' always release when done
Tier 3 performance model. CompilePath() pre-parses a path string into a reusable handle. Combined with a parsed JSON handle, GetValueHP() performs the query with zero string parsing and zero memory allocation — ideal for high-frequency loops processing many JSON documents with the same structure.
| Member | Parameters | Returns | Description |
|---|---|---|---|
| CompilePath | path As String | Long | Pre-parse path into an internal segment list. Returns a path handle (>0). Raises E_INVALIDARG on invalid path syntax. |
| ReleasePath | pathHandle As Long | Free a compiled path handle. Safe to call multiple times. | |
| GetValueHP | jsonHandle As Long, pathHandle As Long | Variant | Query the DOM using a pre-compiled path. Zero parsing, zero allocation (except the returned Variant for strings). Fastest possible query method. |
| GetItemHP | jsonHandle As Long, pathHandle As Long, index As Long | String | Return serialised JSON of the array element at the compiled path, at position index (0-based). |
| CountHP | jsonHandle As Long, pathHandle As Long | Long | Return element or member count at the compiled path. |
| ExistsHP | jsonHandle As Long, pathHandle As Long | Boolean | Return True if the compiled path exists in the DOM. |
Compiled Path Example — High-Frequency Processing
Dim j As Object
Set j = CreateObject("LiteView2.Json")
' Compile the paths once outside the loop
Dim ppName As Long : ppName = j.CompilePath("user.name")
Dim ppScore As Long : ppScore = j.CompilePath("user.score")
' Process thousands of JSON documents — minimal overhead per iteration
Dim i As Long
For i = 1 To 50000
Dim h As Long
h = j.Parse(GetJsonForRow(i)) ' parse each document
Dim name As String : name = j.GetValueHP(h, ppName) ' zero alloc
Dim score As Double : score = j.GetValueHP(h, ppScore) ' zero alloc
ProcessRow name, score
j.Release h
Next i
' Release path handles when fully done
j.ReleasePath ppName
j.ReleasePath ppScore
Query multiple paths in a single call. The input is a 1D Variant array of path strings (for GetValues/GetValuesH) or path handles (for GetValuesHP). Returns a parallel 1D Variant array of results.
| Member | Parameters | Returns | Description |
|---|---|---|---|
| GetValues | json As String, pathsArray As Variant | Variant (array) | Stateless bulk query. Parse json once and return an array of typed values for each path in pathsArray. |
| GetValuesH | handle As Long, pathsArray As Variant | Variant (array) | DOM handle bulk query. Query a pre-parsed DOM for multiple paths in one call. |
| GetValuesHP | handle As Long, pathHandlesArray As Variant | Variant (array) | Compiled path bulk query. Supply an array of path handles — each query is zero-allocation. Fastest batch extraction method. |
Bulk Query Example
Dim j As Object
Set j = CreateObject("LiteView2.Json")
Dim js As String
js = "{""name"":""Alice"",""age"":30,""city"":""London"",""score"":98.5}"
' GetValues — stateless bulk (parses once internally)
Dim paths(3) As Variant
paths(0) = "name" : paths(1) = "age" : paths(2) = "city" : paths(3) = "score"
Dim results As Variant
results = j.GetValues(js, paths)
' results(0) = "Alice", results(1) = 30, results(2) = "London", results(3) = 98.5
' GetValuesHP — maximum performance with compiled paths
Dim pp(3) As Variant
pp(0) = j.CompilePath("name")
pp(1) = j.CompilePath("age")
pp(2) = j.CompilePath("city")
pp(3) = j.CompilePath("score")
Dim h As Long
h = j.Parse(js)
results = j.GetValuesHP(h, pp) ' zero allocation per result (except strings)
j.Release h
' Release path handles when fully done
Dim k As Long
For k = 0 To 3
j.ReleasePath pp(k)
Next k
| Property | Type | Default | Range | Description |
|---|---|---|---|---|
| MaxSize | Long (get/let) | 52428800 (50 MB) | 1024 – 524288000 | Maximum allowed JSON byte count for Parse(), ToArray(), and ToRowArray(), and the maximum DOM memory budget. Checked before allocation. Values outside the range are clamped silently. |
MaxSize Example
Dim j As Object
Set j = CreateObject("LiteView2.Json")
' Reduce limit to 1 MB for untrusted input
j.MaxSize = 1048576
' Increase limit to 100 MB for known large data
j.MaxSize = 104857600
Debug.Print j.MaxSize ' → 104857600