Skip to content

Image To Json

With the Image to Json tool, you can convert your Image file into a Json file. The following examples show how to upload a test Image file and convert it into a Json file using Java, Python languages.

java
// Create a client
CPDFClient client = new CPDFClient(publicKey,secretKey);

// Create a task
// Create an example of a Image to Json task
CPDFCreateTaskResult result = client.createTask(CPDFConversionEnum.IMAGE_TO_JSON);

// Get a task id
String taskId = result.getTaskId();

// File handling parameter settings
CIMGToJsonParameter fileParameter = new CIMGToJsonParameter();
fileParameter.setIsAllowOcr(CIMGToJsonParameter.IS_ALLOW_OCR);

// Upload files
client.uploadFile(new File("test.jpg"), taskId, fileParameter);

// Execute task
client.executeTask(taskId);

// Query TaskInfo
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
Python
# Create a client
client = CPDFClient(public_key, secret_key)

# Create a task
# Create an example of a Image to Json task
create_task_result = client.create_task(CPDFConversionEnum.IMAGE_TO_JSON)

# Get a task id
task_id = create_task_result.task_id

# File handling parameter settings
file_parameter = ImageToJSONParameter()
file_parameter.is_allow_ocr = file_parameter.ALLOW_OCR

# Upload files
client.upload_file('test.png', task_id, file_parameter)

# Execute task
client.execute_task(task_id)

# Query TaskInfo
task_info = client.get_task_info(task_id)

Result:

File TypeDescription
.zipThe Json file zip after the transfer process is completed.