DumpJSON
Dumps a json from context key input, and returns a json object string result.
python · Common Scripts
Details
| ID | DumpJSON |
|---|---|
| Language | python |
| From Version | 5.0.0 |
| Docker Image | demisto/python3:3.12.13.10404775 |
| Tags | Utility |
README
Dumps a JSON from the context key input, and returns a JSON object string result.
Script Data
| Name | Description |
|---|---|
| Script Type | python3 |
| Tags | Utility |
Inputs
| Argument Name | Description |
|---|---|
| key | The context path to the JSON object. |
Outputs
| Path | Description | Type |
|---|---|---|
| JsonStr | The JSON object as a string. | Unknown |
import json import demistomock as demisto from DumpJSON import main def test_dump_json(mocker): """ Given: - Key `Level1.Level2` to dump the object nested under it When: - Run DumpJSON Then: - Ensure expected string value is stored in context and returned from the script """ context = { "Level1": { "Level2": { "Level3": "value", } } } mocker.patch.object(demisto, "args", return_value={"key": "Level1.Level2"}) mocker.patch.object(demisto, "context", return_value=context) mocker.patch.object(demisto, "setContext") mocker.patch.object(demisto, "results") expected_response = json.dumps(context["Level1"]["Level2"]) main() demisto.setContext.assert_called_with("JsonStr", expected_response) demisto.results.assert_called_with(expected_response)