ConvertXmlFileToJson

Converts XML file entry to JSON format

python · Common Scripts

Details

IDConvertXmlFileToJson
Languagepython
From Version5.0.0
Docker Imagedemisto/xml-feed:1.0.0.10133006
TagsUtility

README

Converts a XML file entry into JSON format.

Script Data


Name Description
Script Type javascript
Tags Utility

Inputs


Argument Name Description
entryID The entry ID of a valid XML file to convert to JSON format.
contextKey The context key to push the JSON result to.
verbose Prints the JSON result to War Room.

Outputs


There are no outputs for this script.

import demistomock as demisto


def test_convert_file(mocker):
    """
    Given:
        - xml file to convert
    When:
        - running convert XML to Json script
    Then:
        - validate the output of the conversion is as expected
    """
    from ConvertXmlFileToJson import convert_file

    mocker.patch.object(demisto, "getFilePath", return_value={"path": "./test_data/input.xml"})
    res = mocker.patch.object(demisto, "setContext")
    convert_file(entry_id="mock_entry", verbose=False, context_key="Test")
    expected_result = {"note": {"to": "Tove", "from": "Jani", "heading": "Reminder", "body": "Don't forget me this weekend!"}}
    assert res.call_args[0][1] == expected_result