python_help
python_help

Reputation: 41

Removing a character from json output

This is the JSON output I will be receiving:

{
    "status": "success",
    "data": {
        "@Response": "1",
        "@ErrorNumber": "0",
        "@ErrorDescription": "",
        "@ErrorDisplay": "1",
        "Transactions": [
            {
                "@Account": "xxxxxxxxxx055819",
                "@TranDate": "04/09/2020",
                "@PostDate": "04/09/2020",
                "@Description": "ValueLoad",
                "@Reference": "",
                "@Amt": "50"
            },
            {
                "@Account": "xxxxxxxxxx055819",
                "@TranDate": "04/22/2020",
                "@PostDate": "04/22/2020",
                "@Description": "Balance Adjustment Debit Cardholder",
                "@Reference": "",
                "@Amt": "-10"
            }
        ]
    },
    "meta": {}
}

However, we need this code passed to our front end and the @ symbols will cause errors with variable conversion.

How can I strip the @ symbol from the variables below?

Thanks!

Upvotes: 1

Views: 34

Answers (2)

Ayush Pallav
Ayush Pallav

Reputation: 1057

You can do something like this. If your json is stored in initial_json variable, this will remove all @ symbols,

import re
import json


final_json = json.loads(re.sub('@', '', json.dumps(initial_json)))

Upvotes: 1

Josh Patra
Josh Patra

Reputation: 1

You can try using a regex to take only what you need and remove the rest.

Upvotes: 0

Related Questions