Isa
Isa

Reputation: 145

Extract substring from text using python

I have some values in a column that looks like this:

{"template":{"module":[{"id":"module-12","header":[{"id":"title","value":"Cycle in Comfort","decorators":[]}],"paragraph":[{"id":"description","value":["This folding exercise bike features a heavily-padded seat and backrest for your comfort."]

Is there any way I can extract information from it and paste it in other columns? Information that need to be extracted:

module-12
Cycle in Comfort
This folding exercise bike features a heavily-padded seat and backrest for your comfort

Any advice on extracting the needed information?

Upvotes: 0

Views: 38

Answers (1)

adir abargil
adir abargil

Reputation: 5745

assuming your dictionary object name mydict :

item = mydict["template"]['module'][0]
module_12 = item['id']
header = item['header'][0]
cycle = header['value']
paragraph = item['paragraph'][0]
text = paragraph['value']

print(module_12)
>>> module-12
print(module_12)
>>> Cycle in Comfort
print(module_12)
>>> This folding exercise bike features a heavily-padded seat and backrest for your comfort

Upvotes: 1

Related Questions