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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -