VBScript
VBScript
Extract PDF from JSON
See more JSON Examples
Demonstrates how to extract a PDF file contained within JSON. The file is represented as a base64 string within the JSON. Note: This example can extract any type of file, not just a PDF file.Chilkat VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
set json = CreateObject("Chilkat.JsonObject")
' Load the JSON.
success = json.LoadFile("qa_data/json/JSR5U.json")
If (success <> 1) Then
outFile.WriteLine(json.LastErrorText)
WScript.Quit
End If
' The JSON we loaded contains this:
' {
' ...
' ...
' "data": {
' "content": "JVBERi0xLjQ..."
' }
' ...
' ...
' }
set sb = CreateObject("Chilkat.StringBuilder")
success = json.StringOfSb("data.content",sb)
set bd = CreateObject("Chilkat.BinData")
success = bd.AppendEncodedSb(sb,"base64")
success = bd.WriteFile("qa_output/a0015.pdf")
outFile.Close