How to convert blueprint json file to csv file?

蓝咒 提交于 2019-12-13 03:31:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!