-4

I'm trying to take some JSON data returned from a REST call to another application and return a new list with dicts with the filtered data. It's not working out all that well and I've been at this for over a week without figuring out a solution. Any guidance would be appreciated.

if r.status_code == 200:
        data = r.json()
        result = []
        for serv_info in data[0]['responseData']['server']:
            result.append({'ip': serv_info['ip'], 'port': serv_info['port'])
            continue
        return result
4
  • 1
    What does the data object look like? What should the result look like?
    – AKX
    Jul 30, 2018 at 18:59
  • 2
    Could you further describe the issue you encounter? Could you include a minimum working example to replicate said issue? Jul 30, 2018 at 19:00
  • Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. Minimal, complete, verifiable example applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described.
    – Prune
    Jul 30, 2018 at 19:17
  • The problem was a total noob mistake. Missing right curly bracket closing the dictionary.
    – mindfury
    Jul 31, 2018 at 13:11

2 Answers 2

0

While appending data to result your are missing curly bracket. Also continue after appending data is really not necessary. I hope below code can help you,

if r.status_code == 200:
    data = r.json()
    result = []
    for serv_info in data[0]['responseData']['server']:
        result.append({'ip': serv_info['ip'], 'port': serv_info['port']})
    return result
0

Thank you all for your quick and helpful answers. After looking at it for a while yesterday with a colleague, he pointed out the not-so-obvious-at-the-time syntax error. Once again, highly appreciated.

--Philip

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.