codegurukool.com · Free coding tutorials & online compiler

Home › Python Tutorial › Python JSON and RegEx

Python JSON and RegEx

Exchange data and search text patterns.

json.dumps turns a dictionary into JSON text and json.loads turns it back. The re module finds patterns in text; [0-9]+ matches one or more digits.

Example code

import json, re
data = {"name": "Ada", "langs": ["Python", "JS"]}
text = json.dumps(data)
print(text)
print(json.loads(text)["langs"][0])
print(re.findall("[0-9]+", "a1 b22 c333"))

Run this code in the online editor

← Python modules, dates and mathPython try...except, None and input →