0

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
King David
  • 500
  • 1
  • 7
  • 20
  • This sounds like a problem easily solved with a tool such as [jq](https://stedolan.github.io/jq/) but it is difficult to provide a more precise answer without some actual data. Can you provide `HDP01_blueprint.json` or identify one of the existing [Ambari Blueprints Examples](https://github.com/uprush/ambari-blueprint-examples) on github that's close enough to your problem so that we may provide more specific suggestions? – jq170727 Sep 05 '17 at 03:21

1 Answers1

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.

Tom V
  • 17
  • 3
Erik
  • 153
  • 8
  • it will be nice if you can advice how to find this script – King David Aug 15 '17 at 15:52
  • What do you mean with: find this script? Do you mean how to write it or how to find it on the computer/internet? – Erik Aug 15 '17 at 18:12
  • how to find it for example json2csv – King David Aug 15 '17 at 18:34
  • You can find here on Stackoverflow some issues regarding this subject: - https://stackoverflow.com/questions/22429762/php-script-to-convert-json-to-csv - https://stackoverflow.com/questions/1871524/how-can-i-convert-json-to-csv Or you can find existing scripts and programs on the internet: https://www.npmjs.com/package/json2csv – Erik Aug 15 '17 at 18:45