using System.Collections.Generic;
using Newtonsoft.Json.Linq;
public static void Main()
'Gibberish !@#$%^&*()__________+': '<----',
'.$ 0=- U': { '..☼§....' : 'DVD read/writer'}
JsonTextReader reader = new JsonTextReader(new StringReader(json));
if (reader.Value != null)
Console.WriteLine("Token: {0}, Value: {1}", reader.TokenType, reader.Value);
Console.WriteLine("Token: {0}", reader.TokenType);
Console.WriteLine("=== Expando Object ===");
dynamic expando = new ExpandoObject();
string result = JsonConvert.SerializeObject(expando, Formatting.Indented);
Console.WriteLine(result);
Console.WriteLine("\n\n=== Dictionary Object ===");
Dictionary<string, object> dictionary =
new Dictionary<string, object>();
dictionary.Add("a", "adf");
dictionary.Add("b", "adf");
dictionary.Add("c", "adf");
dictionary.Add("d", "adf");
result = JsonConvert.SerializeObject(dictionary, Formatting.Indented);
Console.WriteLine(result);
Console.WriteLine("\n\n=== Linq ===");
new JProperty("Records", 5),
new JProperty("Documents",
new JProperty("FileName", "Roof Design Notes.docx"),
new JProperty("DocumentDescription", "Design Drawing Notes"),
new JProperty("FolderPath", @"Document\Design"),
new JProperty("DocumentCustomFields",
from KeyValuePair<string, object> dynamicProperty in dictionary
new JProperty(dynamicProperty.Key, dynamicProperty.Value)
result = JsonConvert.SerializeObject(document, Formatting.Indented);
Console.WriteLine(result);
Console.WriteLine("\n\n=== String Serializer ===");
IEnumerable<string> dynamicProperties = dictionary.Select(property =>
string.Format("\n\t\t\"{0}\":\"{1}\"", property.Key, property.Value));
var docCustomFields = string.Join(",", dynamicProperties);
string jsonString = string.Format("{{\n\t\"DocumentCustomFields\":\n\t{{ {0}\n\t}}\n}}", docCustomFields);
Console.WriteLine(jsonString);