ILV2Json Interface coclass LiteView2Json | Standalone JSON engine | No WebView2 required

Note

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

ConditionReturn ValueVBA Err.Number
Path not foundEmpty (VT_EMPTY)0 (no error)
JSON null valueNull (VT_NULL)0 (no error)
Array index out of rangeEmpty (VT_EMPTY)0 (no error)
Invalid JSON stringE_INVALIDARG — "Invalid JSON at position N"
Invalid handle numberE_HANDLE — "Invalid JSON handle: N"
Invalid path syntaxE_INVALIDARG — "Invalid path syntax at position N"
JSON exceeds MaxSizeE_FAIL — "JSON exceeds maximum size (50MB)"
DOM memory limit exceededE_OUTOFMEMORY — "DOM build exceeded memory limit"
Nesting depth > 256E_FAIL — "JSON nesting depth exceeds 256"
License not activatedE_ACCESSDENIED — "LiteView2 license required"
Tip

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.

Read — Stateless 6 methods

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.

MemberParametersReturnsDescription
GetValuejson As String, path As StringVariantReturn typed value at path. Empty if not found, Null if JSON null. Numeric types return Long or Double; booleans return Boolean.
GetItemjson As String, path As String, index As LongStringReturn the serialised JSON of the array element at path[index] (0-based). Empty string if out of range.
GetKeysjson As String, path As StringStringReturn comma-separated list of object keys at path. Empty string if path points to a non-object.
Countjson As String, path As StringLongReturn number of elements (array) or members (object) at path. Returns 0 if path not found or value is scalar.
Existsjson As String, path As StringBooleanReturn True if the path exists in the JSON (even if the value is null).
IsValidjson As StringBooleanReturn 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)
Write — Stateless 8 methods

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.

MemberParametersReturnsDescription
CreateObjectStringReturn an empty JSON object: {}
CreateArrayStringReturn an empty JSON array: []
SetValuejson As String, path As String, value As VariantStringSet (or add) the value at path. Intermediate objects are created automatically. Accepts String, Long, Double, Boolean, or Null.
Removejson As String, path As StringStringRemove the key or array element at path. No-op if path does not exist.
Appendjson As String, path As String, value As VariantStringAppend value to the array at path. The target must be an array.
Insertjson As String, path As String, index As Long, value As VariantStringInsert value into the array at path before position index (0-based).
Clearjson As String, path As StringStringClear all elements from the array or object at path, leaving it empty.
Mergejson1 As String, json2 As String, deep As BooleanStringMerge 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}
Transform — Stateless 8 methods

Structural transformation methods. All accept a JSON string and return a transformed string or SAFEARRAY.

MemberParametersReturnsDescription
PrettyPrintjson As StringStringReturn a human-readable, indented version of json.
Flattenjson As StringStringFlatten a nested JSON object into dot-path keys: {"a":{"b":1}}{"a.b":1}.
Unflattenjson As StringStringReverse of Flatten — expand dot-path keys back into nested objects.
ToArrayjson As StringVariant (1D array)Convert a JSON array to a VBA Variant containing a 1-based String() array of serialised JSON elements. Subject to MaxSize limit.
ToRowArrayjson As StringVariant (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.
BuildJsoninputData As VariantStringConvert a VBA value to a JSON string. Accepts String, Long, Double, Boolean, Null, or a 1D/2D SAFEARRAY of Variants.
UnwrapStringjsonValue As StringStringIf jsonValue is a JSON string literal (double-encoded), unwrap one layer and unescape all JSON sequences (\", \\, \n, \uXXXX, etc.). Otherwise return unchanged.
Compactjson As String, path As StringStringRemove 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}]}
Handle Model — JSON Handles 8 methods

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.

Warning

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.

MemberParametersReturnsDescription
Parsejson As StringLongParse 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.
Releasehandle As LongFree the DOM tree for handle. Safe to call multiple times on the same handle.
ReleaseAllFree all JSON handles and release all DOM memory. Use at form unload or module cleanup.
GetValueHhandle As Long, path As StringVariantReturn typed value at path from the pre-built DOM. Raises E_HANDLE on invalid handle.
GetItemHhandle As Long, path As String, index As LongStringReturn serialised JSON of the array element at path[index] (0-based).
GetKeysHhandle As Long, path As StringStringReturn comma-separated keys of the object at path.
CountHhandle As Long, path As StringLongReturn number of elements (array) or members (object) at path.
ExistsHhandle As Long, path As StringBooleanReturn 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
Handle Model — Compiled Paths 6 methods

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.

MemberParametersReturnsDescription
CompilePathpath As StringLongPre-parse path into an internal segment list. Returns a path handle (>0). Raises E_INVALIDARG on invalid path syntax.
ReleasePathpathHandle As LongFree a compiled path handle. Safe to call multiple times.
GetValueHPjsonHandle As Long, pathHandle As LongVariantQuery the DOM using a pre-compiled path. Zero parsing, zero allocation (except the returned Variant for strings). Fastest possible query method.
GetItemHPjsonHandle As Long, pathHandle As Long, index As LongStringReturn serialised JSON of the array element at the compiled path, at position index (0-based).
CountHPjsonHandle As Long, pathHandle As LongLongReturn element or member count at the compiled path.
ExistsHPjsonHandle As Long, pathHandle As LongBooleanReturn 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
Bulk Operations 3 methods

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.

MemberParametersReturnsDescription
GetValuesjson As String, pathsArray As VariantVariant (array)Stateless bulk query. Parse json once and return an array of typed values for each path in pathsArray.
GetValuesHhandle As Long, pathsArray As VariantVariant (array)DOM handle bulk query. Query a pre-parsed DOM for multiple paths in one call.
GetValuesHPhandle As Long, pathHandlesArray As VariantVariant (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
Properties 1 property
PropertyTypeDefaultRangeDescription
MaxSizeLong (get/let)52428800 (50 MB)1024 – 524288000Maximum 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
Explore More:
Core API | Events | JSON | Browser Pool | Enumerations