1. import json
  2. import sys
  3. def export_sandbox_results(results, output_file="sandbox_results.json"):
  4. """
  5. Exports sandbox results to a JSON file with minimal memory usage.
  6. Args:
  7. results (list): A list of sandbox entry results (dictionaries).
  8. output_file (str): The name of the output JSON file.
  9. """
  10. try:
  11. with open(output_file, 'w') as f:
  12. json.dump(results, f, indent=4) # Serialize to JSON with indentation
  13. print(f"Sandbox results exported to {output_file}")
  14. except Exception as e:
  15. print(f"Error exporting results: {e}")
  16. if __name__ == '__main__':
  17. # Example Usage (replace with your actual results)
  18. sample_results = [
  19. {"entry_id": 1, "status": "success", "output": "Result 1"},
  20. {"entry_id": 2, "status": "failure", "output": "Error message"},
  21. {"entry_id": 3, "status": "success", "output": "Result 3"}
  22. ]
  23. export_sandbox_results(sample_results)

Add your comment