0

I am using requests.get to get an output.[{"id": "e644b06c-8f5b-4bdf-84a0-7266dffc6979", "securityResourceId": "e48e8536-02ff-424d-856a-dab30af23919", "name": "helloWorld", So in the name tag i need to search if it contains xyz and if it does append that name to an array.If you could help id be obliged.Thanks

2 Answers 2

1

you can add .json() to the end of a request to get a dict out of that request (if the request returned a json).

arr = []
dict = requests.get('website').json()
if 'xyz' in dict.get('name'):
    arr.append(dict['name'])
Sign up to request clarification or add additional context in comments.

Comments

0

you can parse JSON into dictionary using json library.

after that you can search the contents with either re or fuzzywuzzy to get matching pattern.

snippet:

import json, re
input_string = '[{"test":"something"},{"xyz":"something else","foo":"bar"}]'
obj = json.loads(input_string)
arr = []
for item in obj:
   for key in item:
       match = re.match("xyz",key)
       if match is not None:
          arr.append(item)
          continue

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.