Sample code for 30+ languages & platforms
React Native

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 React Native Downloads

React Native
import { BinData, JsonObject, StringBuilder } from '@chilkat/react-native'

function chilkatExample() {
  const json = new JsonObject();

  // Load the JSON.
  try {
    json.loadFile('qa_data/json/JSR5U.json');
  } catch {
    console.log(json.lastErrorText);
    return;
  }

  // The JSON we loaded contains this:

  // 	{
  // 	...
  // 	...
  // 	  "data": {
  // 	    "content": "JVBERi0xLjQ..."
  // 	  }
  // 	...
  // 	...
  // 	}

  const sb = new StringBuilder();
  json.stringOfSb('data.content', sb);

  const bd = new BinData();
  bd.appendEncodedSb(sb, 'base64');

  bd.writeFile('qa_output/a0015.pdf');
}