JsonUtility 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package JsonUtility --version 1.1.0                
NuGet\Install-Package JsonUtility -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JsonUtility" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonUtility --version 1.1.0                
#r "nuget: JsonUtility, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JsonUtility as a Cake Addin
#addin nuget:?package=JsonUtility&version=1.1.0

// Install JsonUtility as a Cake Tool
#tool nuget:?package=JsonUtility&version=1.1.0                
public partial class JsonUtilityTester : Form
{
    public JsonUtilityTester()
    {
        Button button = new Button() { Text = "Open", Dock = DockStyle.Top, Parent = this, };
        button.Click += (sender, e) =>
        {
            OpenFileDialog ofd = new OpenFileDialog() { InitialDirectory = Application.StartupPath, };
            /** select a file created by clickling by Create Button or create .\text.txt before and paste
             {"name":"foo", "age":"50", "children":{"name":"bar", "age":"20", "gender":"female","hobby":["tennis","swimming","walking"]}}
            */
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                using (System.IO.StreamReader sr = new System.IO.StreamReader(ofd.FileName))
                {
                    var text = sr.ReadToEnd();
                    var dic = JsonUtility.JsonParser.GetAllValuesAsDic(text);
                    var msg = string.Join(Environment.NewLine,
                        dic.Select(x => string.Format("{0}={1}", x.Key, x.Value)).Take(
                        dic.Keys.Count > 30 ? 30 : dic.Keys.Count));
                    MessageBox.Show(msg);


                    /** necessary to add Newtonsoft.Json */
                    var json = Newtonsoft.Json.JsonConvert.DeserializeObject(text);
                    //var json = JsonUtility.JsonParser.Deserialize(text);

                    var dic2 = JsonUtility.JsonParser.GetAllValuesAsDic(json);
                    var msg2 = string.Join(Environment.NewLine,
                        dic2.Select(x => string.Format("{0}={1}", x.Key, x.Value)).Take(
                        dic2.Keys.Count > 30 ? 30 : dic2.Keys.Count));
                    MessageBox.Show(msg2);

                }

                //Open as binary
                using (System.IO.FileStream fs = new System.IO.FileStream(ofd.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                {
                    var binaryData = new byte[fs.Length];
                    fs.Read(binaryData, 0, binaryData.Length);

                    var dic1 = JsonUtility.JsonParser.GetAllValuesAsDic(binaryData);
                    var msg1 = string.Join(Environment.NewLine,
                        dic1.Select(x => string.Format("{0}={1}", x.Key, x.Value)).Take(
                        dic1.Keys.Count > 30 ? 30 : dic1.Keys.Count));
                    MessageBox.Show(msg1, "Open as binary");
                }
            }

        };

        Button buttonCreate = new Button() { Text = "Create", Dock = DockStyle.Top, Parent = this, };
        buttonCreate.Click += (sender, e) =>
        {
            /* Want to create below
               {"name":"foo", "age":"50", "children":{"name":"bar", "age":"20", "gender":"female","hobby":["tennis","swimming","walking"]}}
            */

            /** Create JObject. Same as 
            var jobj = JsonUtility.JsonCreator.CreateEmptyJObject();
            JsonUtility.JsonCreator.AddOrUpdateValue(jobj, "name", "foo");
            Or
            var jobj= new Newtonsoft.Json.Linq.JObject();
            */

            var jobj = JsonUtility.JsonCreator.CreateJObject(
                new KeyValuePair<string, object>("name", "foo"));

            JsonUtility.JsonCreator.AddOrUpdateValue(jobj, "age", "50");

            /** Create JArray */
            var jarrayHobby = JsonUtility.JsonCreator.CreateJArray();
            jarrayHobby.Add("tennis");
            jarrayHobby.Add("swimming");
            jarrayHobby.Add("walking");

            var jobjChildren = JsonUtility.JsonCreator.CreateEmptyJObject();
            JsonUtility.JsonCreator.AddOrUpdateValue(jobjChildren, "name","bar");
            JsonUtility.JsonCreator.AddOrUpdateValue(jobjChildren, "age", "20");
            JsonUtility.JsonCreator.AddOrUpdateValue(jobjChildren, "gender", "female");
            JsonUtility.JsonCreator.AddOrUpdateValue(jobjChildren, "hobby", jarrayHobby);
            JsonUtility.JsonCreator.AddOrUpdateValue(jobj, "children", jobjChildren);

            var dic = JsonUtility.JsonParser.GetAllValuesAsDic(jobj);
            var msg = string.Join(Environment.NewLine,
                dic.Select(x => string.Format("{0}={1}", x.Key, x.Value)).Take(
                dic.Keys.Count > 30 ? 30 : dic.Keys.Count));

            MessageBox.Show(msg);

            var dstfn = string.Format(".\\{0:yyyyMMdd_HHmmss}_json.csv", DateTime.Now);
            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(dstfn, false, Encoding.UTF8))
            {
                sw.Write(JsonUtility.JsonParser.Serialize(jobj));
            }

            MessageBox.Show(string.Format("Save as {0}", dstfn) );

        };

        StartPosition = FormStartPosition.CenterScreen;

    }
}
Product Compatible and additional computed target framework versions.
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.2 204 7/15/2024
1.1.1 434 11/8/2023
1.1.0.1 795 9/9/2022
1.1.0 560 4/9/2022
1.0.7 479 10/13/2021