How can I strip new line character from my response

25 Views Asked by At

My code is -

import json

f = open('AcceptanceCriteria.json')
data = json.load(f,strict=False)
for criteria in data['acceptanceCriteria']: 
    print(criteria)

Response getting is -

{'criteria': 'Assets are grouped at a Fabric level with each Fabric consisting of APICs and\nSwitches.'}
{'criteria': 'Cloud Network Software landing page shows the specified columns: Risk Level,\nFabric, Software Type, Current Release, Selected Release, Assets, and Suggestions.'}

how can I get rid of \n from the response

1

There are 1 best solutions below

3
MasNotsram On

It looks like the content of each criteria entry is an object with a string valued property with key 'criteria', so the below should work fine:

I renamed the 'criteria' variable to make it more obvious it's an entry in an array. Updated to correct access syntax for string key in the dictionary structure, as pointed out by Nick in the comments

for criteriaEntry in data['acceptanceCriteria']: 
    print(criteriaEntry['criteria'].replace("\n", ""))