Attribute VB_Name = "JsonDebugPrint"
Option Explicit


Public Sub TestPrintJSON()
    PrintJSON ParseJson("[1,2,3]")
    PrintJSON ParseJson("[{""a"":123,""b"":[56,7,78]}]")
End Sub

' This is definitely NOT a pretty printer. It was written merely as a debugging
' tool to make sense of the objects that come out of JsonConverter.ParseJSON.
' It doesn't format in the best way possible, but it does provide a semi-readable
' view of the data in the JSON object.
'                                               Phil Runninger 3/1/2023
'
Public Sub PrintJSON(obj As Variant, Optional level As Integer = 0)
    Dim itm As Variant
    Dim first As Boolean
    Select Case TypeName(obj)
        Case "Dictionary"
            Debug.Print String(level * 2, " "); "{"
            first = True
            For Each itm In obj
                If Not first Then Debug.Print String((level + 1) * 2, " "); ","
                first = False
                Debug.Print String((level + 1) * 2, " "); itm; ":";
                PrintJSON obj(itm), level + 1
            Next
            Debug.Print String(level * 2, " "); "}"
        Case "Collection"
            Debug.Print String(level * 2, " "); "["
            first = True
            For Each itm In obj
                If Not first Then Debug.Print String(level * 2, " "); ","
                first = False
                PrintJSON itm, level + 1
            Next
            Debug.Print String(level * 2, " "); "]"
        Case Else
            Debug.Print String(level * 2, " "); obj;
    End Select
End Sub

