Let say JSON string is given, and I want to validate using C#. We all know that JSON string has the following format
string jsonStr = {"Id":123,"Value":"asdf","Time":"adf","isGood":false}];
I want to take care of Number, String, Boolean, Null types for now. I can see that the pattern of JSON is
{ + " + String + " + : + (Number)|(Boolean)|(" + String + ")|(Null) + , + ... + } + ]
// ... means one or more
I am really new to Regular Expression, so I have no idea... Could anyone kindly help me out?
EDIT
Sorry, I am not using JSON.NET and I don't want to use it. I found that using Regex is the only way to validate my JSON string. If there is any suggestion, I will go for it. Thank you
EDIT2
My question is "How to validate JSON using Regex", and not "Should I validate JSON using Regex". You guys probably understand that company has own policy "not to use 3rd-party resource". What should I do guys? I am just NOT ALLOWED to use it.
I'm going to put this at the top of my JSON-knowledge-lacking attempt so everyone sees it:
Basically, to everyone who's losing their minds over this, modern regex implementations have gone farther than formal cs regular expressions, and as a result are no longer bound to representing only regular languages, because of things like backreferences and recursion. Ergo, we can now match things with regex that aren't regular languages, which, I'll give you, is rather unintuitive.
I'll leave my attempt here for posterity anyway.
This pattern:
{("\w+":(\d+|"\w+"|true|false|null))+}\]
should match what you're asking for if I understand you correctly, but from the storm of angry posts, it seems that you probably shouldn't use regex.