tags:

views:

18

answers:

3

I a JSON string that contains a Regular Expression: like - { "pattern": /[a-z0-9]+/i }

Is there any easy way to parse this in .NET and get resulting object/data-structure that I can use further?

I tried JSON.NET's JObject.Parse() method but it throws an exception.

Thanks in advance!

+1  A: 

That isn't valid JSON. Regexp literals are not allowed. You could come up with some manual parsing code, but the better solution is to fix the code that outputs that to convert the regexp literal to a string.

You can use JSONLint to easily check any JSON.

Matthew Flaschen
Got it. thanks!
Ishaan
A: 

This json data should probably look like this:

{ "pattern": "/[a-z0-9]+/i" }

your parser is complaining, because the json your passed is not well formed.

Grzenio
+1  A: 

If you can't fix the source (which is actually the right answer), you could try to parse it manually, but you'll have a hard time accounting for the Regex, since almost any character is valid in a regex (what if it contains : and { or })?

Curtis