Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oJson
LOCAL oSb
LOCAL oBd
nSuccess := 0
oJson := CreateObject("Chilkat.JsonObject")
// Load the JSON.
nSuccess := oJson:LoadFile("qa_data/json/JSR5U.json")
IF (nSuccess != 1)
? oJson:LastErrorText
oJson:destroy()
RETURN
ENDIF
// The JSON we loaded contains this:
// {
// ...
// ...
// "data": {
// "content": "JVBERi0xLjQ..."
// }
// ...
// ...
// }
oSb := CreateObject("Chilkat.StringBuilder")
oJson:StringOfSb("data.content", oSb)
oBd := CreateObject("Chilkat.BinData")
oBd:AppendEncodedSb(oSb, "base64")
nSuccess := oBd:WriteFile("qa_output/a0015.pdf")
oJson:destroy()
oSb:destroy()
oBd:destroy()