如何将blueprint json文件转换为csv文件? [英] How to convert blueprint json file to csv file?
问题描述
如何将blueprint json文件转换为csv文件?
我的目标是将所有属性参数转换为amabri集群中的csv文件
示例 - 如何从ambari集群生成新的blueprint.json文件
curl - u admin:admin -HX-Requested-By:ambari-X GET http://10.23.4.122:8080/api/v1/clusters/HDP01?format=blueprint -o /tmp/HDP01_blueprint.json
预期结果示例:(来自所有配置类型的json文件中的所有参数应该位于csv文件中) p>
autopurge.purgeInterval,512
dataDir,/ hadoop / zookeeper
autopurge.snapRetainCount,10
clientPort,2181
initLimit,11
tickTime,2000
syncLimit,5
您可以编写自己的脚本来完成此转换。 读取JSON并创建csv文件。
阅读JSON
$ fileContent = file_get_contents('/ tmp / HDP01_blueprint.json');
$ parsedContent = json_decode($ fileContent,true);
在此之后,内容作为关联数组存储在$ parsedContent变量中。使用这个数组,你可以将你想要的值写入一个csv文件。
如果你愿意,你甚至可以让脚本为你取得JSON字符串。
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
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.
这篇关于如何将blueprint json文件转换为csv文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!