internal static string JsonSerializePayload(EventEntry entry)
        {
            try
            {
                using (var writer = new StringWriter(CultureInfo.InvariantCulture))
                using (var jsonWriter = new JsonTextWriter(writer) { Formatting = Transformalize.Libs.Newtonsoft.Json.Formatting.Indented, CloseOutput = false })
                {
                    EventEntryUtil.JsonWritePayload(jsonWriter, entry);
                    jsonWriter.Flush();
                    return writer.ToString();
                }
            }
            catch (JsonWriterException jwe)
            {
                SemanticLoggingEventSource.Log.EventEntrySerializePayloadFailed(jwe.ToString());

                var errorDictionary = new Dictionary<string, object>
                { 
                    {
                        "Error",
                        string.Format(CultureInfo.CurrentCulture, Resources.JsonSerializationError, jwe.Message)
                    }
                };

                return JsonConvert.SerializeObject(errorDictionary, Transformalize.Libs.Newtonsoft.Json.Formatting.Indented);
            }
        }
        internal static string JsonSerializePayload(IEnumerable<KeyValuePair<string, object>> payload)
        {
            try
            {
                using (var writer = new StringWriter(CultureInfo.InvariantCulture))
                using (var jsonWriter = new JsonTextWriter(writer) { Formatting = Transformalize.Libs.Newtonsoft.Json.Formatting.Indented, CloseOutput = false })
                {
                    jsonWriter.WriteStartObject();

                    foreach (var item in payload)
                    {
                        JsonWriteProperty(jsonWriter, item.Key, item.Value);
                    }

                    jsonWriter.WriteEndObject();
                    jsonWriter.Flush();
                    return writer.ToString();
                }
            }
            catch (JsonWriterException jwe)
            {
                SemanticLoggingEventSource.Log.EventEntrySerializePayloadFailed(jwe.ToString());

                var errorDictionary = new Dictionary<string, object>
                { 
                    {
                        "Error",
                        string.Format(CultureInfo.CurrentCulture, "JSON Serialization Error {0}", jwe.Message)
                    }
                };

                return JsonConvert.SerializeObject(errorDictionary, Transformalize.Libs.Newtonsoft.Json.Formatting.Indented);
            }
        }
 public string Handle(Process[] processes) {
     var sw = new StringWriter();
     var writer = new JsonTextWriter(sw);
     foreach (var process in processes) {
         writer.WriteStartArray();
         foreach (var row in process.Results) {
             writer.WriteStartArray();
             foreach (var alias in process.OutputFields().Aliases()) {
                 writer.WriteValue(row[alias]);
             }
             writer.WriteEndArray();
         }
         writer.WriteEndArray();
     }
     writer.Flush();
     return sw.ToString();
 }
 public static string LogsToJson(IEnumerable<string[]> logs) {
     var sw = new StringWriter();
     var writer = new JsonTextWriter(sw);
     writer.WriteStartArray();
     foreach (var log in logs) {
         if (log.Length <= 4)
             continue;
         writer.WriteStartObject(); //add
         writer.WritePropertyName("time");
         writer.WriteValue(log[0]);
         writer.WritePropertyName("level");
         writer.WriteValue(log[1].TrimEnd());
         writer.WritePropertyName("process");
         writer.WriteValue(log[2]);
         writer.WritePropertyName("entity");
         writer.WriteValue(log[3]);
         writer.WritePropertyName("message");
         writer.WriteValue(log[4].TrimEnd(new[] { ' ', '\r', '\n' }));
         writer.WriteEndObject(); //add
     }
     writer.WriteEndArray();
     writer.Flush();
     return sw.ToString();
 }