-
Notifications
You must be signed in to change notification settings - Fork 0
Response Format JSON
Besides the usual terminal output, DBM-Db2 Plug-in commands can return data in the JSON format using the --rfj
parameter. This feature allows processing data in automation without redundant parsing. The following article describes the structure of such response, and provides examples of how it can be used in programming languages like Python.
For more information about the Python usage, see Python samples.
The following example shows the typical output of the command execution with JSON output enabled:
{
"success": false,
"exitCode": 1,
"message": "Execution failed. Failure details saved to error.log\nRestart token: 840413D5D132CB8A7149C85940B7FBA4",
"stdout": "",
"stderr": "\u001b[31mCommand Error:\u001b[39m\n\u001b[31m\u001b[39mExecution failed. Failure details saved to error.log\nRestart token: 840413D5D132CB8A7149C85940B7FBA4\n",
"data": {
"files": {
"errorFile": "error.log"
},
"attributes": {
"restartToken": "840413D5D132CB8A7149C85940B7FBA4"
}
},
"error": {
"msg": "Execution failed. Failure details saved to error.log\nRestart token: 840413D5D132CB8A7149C85940B7FBA4"
}
}
The data
property contains additional information, so that you do not need to parse the message to retrieve it.
The data.files
property may contain the following properties based on the output files available for a command
executed:
- ddlFile
- summaryFile
- impactFile
- compareScript
- recoveryScript
- migrateScript
- errorFile
The data.attributes
property may contain the following properties:
- restartToken - Available for
execute
commands that failed. - hasObjectChanges - Available for the
compare ddl
command.false
when there are 0 creates, alters, and drops - otherwisetrue
.
The data
structure is persistent across commands. If there is no data, the field remains empty:
...
"files": {},
"attributes": {}
Prerequisites: Python >=3.11.0
-
JSON output always includes
data
,files
, andattributes
levels, so no verification is required. -
Parse JSON response and get files dictionary:
res = json.loads(response) files = res.get("data").get("files")
-
Get the file you need based on the command executed and outcome (success/failure):
files.get('errorFile') # -> string relative path | None
For more information about processing JSON response in python, see Python samples.