using System.Collections.Generic;
using System.Text.RegularExpressions;
public static void Main()
""_id"" : ObjectId(""5a676641ecd0a32a385f61bb""),
""$Event.Alert.State"" : false
Console.WriteLine(MongoEncode(text));
public static string MongoEncode(string JSON)
string pattern = @"([,{]\s*"")(\$)(.+""\s*:)";
JSON = Regex.Replace(JSON, pattern, m => m.Groups[1].Value + "#" + m.Groups[3].Value);
pattern = @"([,{]\s*"".+)(\.)(.+""\s*:)";
JSON = Regex.Replace(JSON, pattern, m => m.Groups[1].Value + "#" + m.Groups[3].Value);
} while (tmpJSON!=JSON) ;