问题
How to convert blueprint json file to csv file?
My target is to convert all properties parameters to a csv file from the amabri cluster
Example – how to generate new fresh blueprint.json file from my ambari cluster
curl -u admin:admin -H "X-Requested-By: ambari" -X GET http://10.23.4.122:8080/api/v1/clusters/HDP01?format=blueprint -o /tmp/HDP01_blueprint.json
example of expected results: ( all parameters from json file from all config types should be in the csv file )
autopurge.purgeInterval,512
dataDir,/hadoop/zookeeper
autopurge.snapRetainCount,10
clientPort,2181
initLimit,11
tickTime,2000
syncLimit,5
回答1:
You could write your own script for doing this conversion.
For example you could use PHP for reading the JSON and creating the csv file exactly the way you want it.
Reading the JSON
$fileContent = file_get_contents('/tmp/HDP01_blueprint.json');
$parsedContent = json_decode($fileContent, true);
After this the content is stored in the $parsedContent variable as an associative array. With this array you can write the values you want to a csv file.
You can even let the script fetch the JSON string for you if you want.
来源:https://stackoverflow.com/questions/45688805/how-to-convert-blueprint-json-file-to-csv-file