CSharp · Console
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
string json = @"{
""Name"": ""Eli"",
""Age"": 4,
""Children"": {
""Moshe"": {
""Age"": 6,
""Characteristics"": ""Nice;Good;""
},
""Yossi"": {
""Age"": 3,
""Characteristics"": ""Hero;Brave""
}
}
}";
string result = Regex.Replace(json, @"(\""Children\""\:(.|\n)*?)(\{(.|\n)*\{(.|\n)*?\}(.|\n)*?\})", (m) =>
{
return (m.Groups[1] + "\"" + Regex.Replace(m.Groups[3].Value.Replace("\n", " "), @"\s+", " ") + "\"");
}
);
Console.WriteLine(result);
}
}