C
C
CodeDog2020-09-05 01:45:58
Python
CodeDog, 2020-09-05 01:45:58

Split json on commas?

This is the json

[{"id":"214115596"},{"id":"2476115554"},{"id":"544664596"},{"id":"215465596"},{"id":"21655596"},{"id":"2154665596"}]


How to make in python so that when parsing json, id are displayed separated by a comma (Example 544664596,21655596)

def autor(chatid):
    strid = str(chatid)
    url2 = 'http://test.loc/apiv2.php?key=1'
    response = requests.get(url2, headers={'User-Agent': 'my agent'})
    for item in response.json()[0]['id']:
        if item == strid:
            return True
    return False

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SirotaKazansky, 2020-09-05
@CodeDog

When python is before primer...

jlist = [{"id":"214115596"},{"id":"2476115554"},{"id":"544664596"},{"id":"215465596"},{"id":"21655596"},{"id":"2154665596"}]
zapetaya=[]
for items in jlist:
    value = int(items['id'])
    zapetaya.append(value)
print (zapetaya)

S
shurshur, 2020-09-05
@shurshur

",".join(list(map(lambda x:x.get("id"), response.json()[0])))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question