I need to get the values of ‘name’ from such string
[{'self': 'https://jira.zxz.su/rest/api/2/component/11207132',
'id': '11207',
'name': 'SEO'},
{'self': 'https://jira.zxz.su/rest/api/2/component/12200123',
'id': '12200',
'name': 'НКК'}]
I want to get an output like 'SEO','HKK'
all in one string.
5
Answers
This should work:
Output:
Explanation:
The list comprehension creates a flat list comprised of values corresponding to the
name
key for every dictionary indata
. Then we simply wrap those elements in quotes andjoin
them in a comma-separated string.You have a list of dictionaries. All you need to do is to iterate over the dictionaries and to keep the
name
key of each one of them:Output:
If your input is not an array or dictionary, but a string you can not directly access the data. You can use
json
:Output:
To get your requested Output you can do:
This will give you:
Depends on how you want your name data stored, but something like this will work:
This should extract and format the names as you indicate:
Putting this into the REPL shows: