using System.Collections.Generic;
public static void Main()
string input = "{\"listingCity\": \"###FieldName:listingCity|Type:string|Required:Yes###\", \"numBedroomsSought\": \"###FieldName:bedrooms|Type:int|Default:0###\",\"listingContactEmail\": null, \"listingPostalCode\": \"###FieldName:listingPostalCode|Type:string|Required:Yes###\", \"listingId\": \"###FieldName:ExternalPropertyRef|Type:string|Required:Yes###\",\"message\": \"###FieldName:message|Type:string|Required:Yes###\", \"globalListingId\": null, \"listingUnit\": \"\", \"listingStreet\": \"###FieldName:listingStreet|Type:string|Required:Yes###\",\"leadType\": \"question\", \"phone\": \"###FieldName:renterPhone|Type:string|FormatPattern:xxxxxxxxxx|ExcludeIfNull:No|Required:No###\", \"numBathroomsSought\": \"###FieldName:bathrooms|Type:float|FormatPattern:00.0|Default:0###\",\"movingDate\": \"###FieldName:moveInDate|Type:date|FormatPattern:yyyyMMdd###\", \"name\": \"###FieldName:firstName|Type:string|Required:yes###,###FieldName:lastName|Type:string|Required:yes###\",\"listingState\": \"###FieldName:listingState|Type:string|Required:Yes###\", \"email\": \"###FieldName:renterEmail|Type:string|FormatPattern:email|Validation:RegEx###\"}";
string[] sections = input.Split(new string[] { "###"}, StringSplitOptions.RemoveEmptyEntries);
var listOfPlacements = new List<string>();
foreach (var section in sections)
Console.WriteLine(section + section.IndexOf("FieldName:") + "\r\n");
if(section.IndexOf("FieldName:") >= 0)
listOfPlacements.Add(section);
foreach (var section in listOfPlacements)
Console.WriteLine(section + "\r\n");
Dictionary<string, ValueWithType> dPlacements = new Dictionary<string, ValueWithType>();
foreach (var s in listOfPlacements)
dPlacements.Add(s, ParseValue(s));
Console.WriteLine("\r\nA1\r\n");
foreach (var kvp in dPlacements)
Console.WriteLine("\r\nKey: {0}, Value: {1}", kvp.Key, kvp.Value.Value);
foreach (var kvp in dPlacements)
if(kvp.Value.Type == "string")
input = input.Replace("###" + kvp.Key + "###", kvp.Value.Value);
input = input.Replace("\"###" + kvp.Key + "###\"", kvp.Value.Value);
Console.WriteLine(input);
public static ValueWithType ParseValue(string y)
var r = ExtractBodyProperties(y);
var returnValueWithType = new ValueWithType();
if (r.FieldName == "listingCity")
Value = "listingCity vale"
if (r.FieldName == "bedrooms")
if (r.FieldName == "listingPostalCode")
if (r.FieldName == "ExternalPropertyRef")
if (r.FieldName == "message")
if (r.FieldName == "listingStreet")
if (r.FieldName == "renterPhone")
if (r.FieldName == "bathrooms")
if (r.FieldName == "moveInDate")
if (r.FieldName == "firstName")
if (r.FieldName == "lastName")
if (r.FieldName == "listingState")
if (r.FieldName == "renterEmail")
Value = "anand@costar.com"
return returnValueWithType;
public static RequestBodyProperty ExtractBodyProperties(string y){
var r = new RequestBodyProperty();
string[] keyValuePairs = y.Split('|');
foreach(var x in keyValuePairs)
if(key.ToLower() == "FieldName".ToLower())
if(key.ToLower() == "Type".ToLower())
if(key.ToLower() == "Required".ToLower())
if(val.ToLower() == "yes")
if(key.ToLower() == "Validation".ToLower())
if(key.ToLower() == "FormatPattern".ToLower())
public static void ExtractProperties(RequestBodyProperty x, string y)
string[] keyValuePairs = y.Split('|');
var keyValueDictionary = new Dictionary<string, string>();
foreach (string pair in keyValuePairs)
string[] parts = pair.Split(':');
keyValueDictionary[key] = value;
foreach (var kvp in keyValueDictionary)
Console.WriteLine("Key:{0}, Value:{1}", kvp.Key.Trim(), kvp.Value.Trim());
public class RequestBodyProperty
public string FieldName {get;set;}
public string Type {get;set;}
public bool Required {get;set;}
public string Validation {get;set;}
public string FormatPattern {get;set;}
public class ValueWithType
public string Type {get;set;}
public string Value {get;set;}