简体   繁体   中英

Regular expression for Replace jSon string

Hey I need a regular expression to replace the matching string with empty.

I have below json

{"session":{"convener_id":null,"convergence":false,"created_at":"2012-06-02T10:00:00","event_id":null,"id":42,"name":"Test Session","next_steps":"","notes":"","room":null,"status":0,"summary":"","time":"10:0","updated_at":"2013-06-03T11:49:45.3397898+05:30","people":null,"comments":null,"convener":null}}

I need a json to replace the null properties to empty so that I don't have any null properties. If any proeprties is null just remove that property. I know regular expression can do the tricks but I am not well versed in regular expression.

I would suggest you to don't look at Regex for this case, instead use JSONParser for .Net. This thread can help you on this issue.

Setting JSONSerializer.NullValueHandling to NullValueHandling.Ignore should resolve your issue.

But if still want to treat JSON response as a plain text and want to do string operations, a call to REPLACE (with empty string) using this regex can help you:

(\"[^"]+\":null,?|,?\"[^"]+\":null)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM