-1

i would like to grep the only value: "INC1301724" from the "display_value":"INC1301724", from the text file: Response.txt below:

print('Response after Snow ticket update : '+response.text) 

value of response.text is:

{"import_set":"ISET1677878","staging_table":"u_incident_create_import","result":[{"transform_map":"Incident Create Import","table":"incident","display_name":"number","display_value":"INC1301724","record_link":"https://example.com/api/now/table/incident/04331234rfgthyjjkkkkllljhfdd","status":"inserted","sys_id":"01234567890"}]}
shailysharma
  • 61
  • 1
  • 5

2 Answers2

0

you just need to search every line for "display_value" then cut the substring with search about index of '"' : this is image of the Solution

with open('response.txt') as file:
for line in file:
    String_Line=line.rstrip()
    if "display_value" in String_Line:
        index1 = String_Line.find ( 'display_value":' )
        Newstring=String_Line[index1+16:]
        print(Newstring)
        new_index_1 = Newstring.find('"')
        print(new_index_1)
        your_string=Newstring[:new_index_1]
        print(your_string)
        
        
    
Hasan
  • 13
  • 3
0

Use json:

json.loads('{"import_set":"ISET1677878","staging_table":"u_incident_create_import","result":[{"transform_map":"Incident Create Import","table":"incident","display_name":"number","display_value":"INC1301724","record_link":"https://example.com/api/now/table/incident/04331234rfgthyjjkkkkllljhfdd","status":"inserted","sys_id":"01234567890"}]}')["result"][0]["display_value"]
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134