0

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.

2
  • You are looking for some pain... Properly parsing nested braces (and correctly handing strings with them i.e. "field:"b{a{a:null") is not easy with regular expressions. Please check answer by Sam on balancing braces in all time favorite on regular expression Commented Jun 3, 2013 at 7:07
  • Can you do that with Javascript? Then all you need to do is delete obj.property where it is null. Otherwise you will probably need to parse json, there is a project called JSON.NET that can help you. Commented Jun 3, 2013 at 7:18

1 Answer 1

3

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.