VBA-tools / VBA-JSON

JSON conversion and parsing for VBA
MIT License
1.79k stars 573 forks source link

JSON all wrapped as an array - Run-Time error : type mismatch #187

Open Sorbier opened 3 years ago

Sorbier commented 3 years ago

Hello,

I'm trying to upload data into an MS Access table from MediaInfo Command Line JSON export [https://mediaarea.net]

MediaInfo.exe" -f --Output=JSON --Logfile=res_1file.json Y:\video\OneFile.m4v

This command creates the following JSON file { "media": { "@ref": "OneFile.m4v", "track": [ { "@type": "General", "Video_Format_List": "HEVC", "Video_Format_WithHint_List": "HEVC", "Video_Codec_List": "HEVC", "Audio_Format_List": "AAC LC", "Audio_Format_WithHint_List": "AAC LC", "Audio_Codec_List": "AAC LC" }, { "@type": "Video", "Format": "HEVC", "Duration": "2173.960" }, { "@type": "Audio", "Format": "AAC", "Format_String": "AAC LC", "Format_Info": "Advanced Audio Codec Low Complexity", "Format_Commercial": "AAC", "Duration": "2173.952" } ] } }

All my code is working properly, accessing all fields from the JSON file.

The problem is when I want to process a set of files (e.g an entire folder)

MediaInfo.exe" -f --Output=JSON --Logfile=res_2file.json Y:\video

In this folder I've got 2 files.

The JSON is now all wrapped as an array [] to handle multiple files.

[ { "media": { "@ref": "Y:file1.m4v", "track": [ { "@type": "General", "Video_Format_List": "HEVC", "Video_Format_WithHint_List": "HEVC", "Video_Codec_List": "HEVC", "Audio_Format_List": "AAC LC", "Audio_Format_WithHint_List": "AAC LC", "Audio_Codec_List": "AAC LC" }, { "@type": "Video", "Format": "HEVC", "Duration": "2173.960" }, { "@type": "Audio", "Format": "AAC", "Duration": "2173.952" } ] } }, { "media": { "@ref": "file2.m4v", "track": [ { "@type": "General", "Video_Format_List": "HEVC", "Video_Format_WithHint_List": "HEVC", "Video_Codec_List": "HEVC", "Audio_Format_List": "AAC LC", "Audio_Format_WithHint_List": "AAC LC", "Audio_Codec_List": "AAC LC" }, { "@type": "Video", "Format": "HEVC", "Duration": "2173.940" }, { "@type": "Audio", "Format": "AAC", "Duration": "2173.952" } ] } } ]

My code is :

Set JsonTS = FSO.OpenTextFile("C:\Video\res_2file.json", ForReading) JsonText = JsonTS.ReadAll JsonTS.Close Set Parsed = JsonConverter.ParseJson(JsonText)

Running it, I've got a Run-Time error '13" : type mismatch at Set Parsed = JsonConverter.ParseJson(JsonText)

Any idea ?

Thanks in advance

Sorbier commented 3 years ago

With an array, JsonConverter.ParseJson returns a Collection, not a Dictionary I replaces Dim Parsed As Dictionary by Dim Parsed As Collection