JsonUnescape

Recursively un-escapes JSON data if escaped JSON is found.

python · Common Scripts

Details

IDJsonUnescape
Languagepython
From Version6.0.0
Docker Imagedemisto/python3-deb:3.12.13.12042988
Tagstransformer

README

Recursively un-escapes JSON data if escaped JSON is found

Script Data


Name Description
Script Type python3
Tags transformer

Inputs


Argument Name Description
value JSON object

Outputs


Path Description Type
JsonUnescape Unescaped JSON Data Unknown
def test_hook():
    """
    Given
    - A string value representing a json
    When
    - Running the hook function
    Then
    - Ensure the string value is converted to json
    """
    from JsonUnescape import hook

    assert hook({"key": "value"}) == {"key": "value"}
    assert hook({"key": "{'key': 'value'}"}) == {"key": "{'key': 'value'}"}


def test_unescape():
    """
    Given
    - A dictionary with a string value
    When
    - Running the unescape function
    Then
    - Ensure the string value is converted to json
    """
    from JsonUnescape import unescape

    assert unescape({"value": "value"}) == "value"
    assert unescape({"value": "{'key': 'value'}"}) == "{'key': 'value'}"