Ability to choose which fields/data we want while exporting JSON rules

XMLWordPrintable

      Currently, our Global Automation Rules export functionality will export a JSON with all the data available, however, this is not a user friendly looking when we need to have an "admin view" of all the rules, to understand simple things like:

      1. Rule ID
      2. Rule Name
      3. Rule State
      4. Rule Scope

      We know that manipulating the JSON could extract this information for us but admins don't have the skills to do it easily.

      Sharing a small Python Script where it will simply parse the Export JSON file from your Global Automation rules and filter out the data above:

      import json
      import csv
      
      # Read JSON data from a file. This should be your export JSON file name.
      with open('input.json', 'r') as json_file:
          data = json.load(json_file)
      
      # Open a CSV file for writing
      with open('output.csv', 'w', newline='') as csv_file:
          csv_writer = csv.writer(csv_file)
      
          # Write the header row
          csv_writer.writerow(['Rule ID', 'Rule Name', 'Rule State', 'Rule Scope'])
      
          # Iterate through the rules array
          for rule in data.get('rules', []):
              # Extract the required fields
              rule_id = rule.get('id', '')
              rule_name = rule.get('name', '')
              rule_state = rule.get('state', '')
      
              # Join the resources list into a single string
              resources = ', '.join(rule.get('ruleScope', {}).get('resources', []))
      
              # Write the row to the CSV file
              csv_writer.writerow([rule_id, rule_name, rule_state, resources])
      
      print("CSV file has been created successfully.")
      

            Assignee:
            Unassigned
            Reporter:
            Bruno Gehlen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: