JsonUtility 1.1.2

dotnet add package JsonUtility --version 1.1.2                
NuGet\Install-Package JsonUtility -Version 1.1.2                
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.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonUtility --version 1.1.2                
#r "nuget: JsonUtility, 1.1.2"                
#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.2

// Install JsonUtility as a Cake Tool
#tool nuget:?package=JsonUtility&version=1.1.2                
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace JsonUtilityTest
{
	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", "200");
				/** Whoops! */
				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 net461 is compatible.  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 (1)

Showing the top 1 NuGet packages that depend on JsonUtility:

Package Downloads
JenkinsUtility

Make build, get build results, download artifacts, and remove builds easily on Jenkins

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.2 187 7/15/2024
1.1.1 433 11/8/2023
1.1.0.1 793 9/9/2022
1.1.0 559 4/9/2022
1.0.7 478 10/13/2021