python - Removing last character of JSON object -
i'm looking way remove last character of line of json, provided it's not curly brace.
i've whole file of json reason of lines end few spaces , 0. i'm trying remove 0 if appears, or skip line if doesn't.
for example: ignore this:
{"menu": { "id": "file", "popup": { "menuitem": [ {"value": "new", "onclick": "createnewdoc()"}, ] } }}
and remove 0 this:
{"menu": { "id": "file", "popup": { "menuitem": [ {"value": "new", "onclick": "createnewdoc()"}, ] } }} 0
i've tried using:
line = line.rstrip('0')
but doesn't seem doing anything.
you can use regular expressions:
import re re.sub(r'0$', '', line)
Comments
Post a Comment