{"id":13652907,"url":"https://github.com/jsonfx/jsonfx","last_synced_at":"2025-04-23T03:31:44.950Z","repository":{"id":1005587,"uuid":"822377","full_name":"jsonfx/jsonfx","owner":"jsonfx","description":"JsonFx v2.0 - JSON serialization framework for .NET","archived":false,"fork":false,"pushed_at":"2016-12-24T03:24:49.000Z","size":3929,"stargazers_count":380,"open_issues_count":20,"forks_count":100,"subscribers_count":45,"default_branch":"master","last_synced_at":"2024-03-26T22:02:43.387Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://jsonfx.net/license","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"mbostock/gistup","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsonfx.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-08-06T22:42:59.000Z","updated_at":"2024-02-08T17:05:13.000Z","dependencies_parsed_at":"2022-07-06T01:02:38.976Z","dependency_job_id":null,"html_url":"https://github.com/jsonfx/jsonfx","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonfx%2Fjsonfx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonfx%2Fjsonfx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonfx%2Fjsonfx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonfx%2Fjsonfx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsonfx","download_url":"https://codeload.github.com/jsonfx/jsonfx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250365668,"owners_count":21418725,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T02:01:03.896Z","updated_at":"2025-04-23T03:31:41.841Z","avatar_url":"https://github.com/jsonfx.png","language":"C#","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"# [JsonFx v2.0][1] - JSON serialization framework for .NET\n## Distributed under the terms of an [MIT-style license][2]\n\n### Compatible Runtimes:\n- .NET Framework 2.0, 3.0, 3.5, and 4.0\n- Silverlight 3.0, 4.0\n- Windows Phone 7\n- Mono Framework 2.6\n\n### Serialization Features:\n- Unified interface for reading / writing [JSON][3], [BSON][4], XML, [JsonML][5]\n- Implements true LINQ-to-JSON (not simply LINQ-to-Objects over JSON types)\n- Naturally deserializes to standard CLR types, not JSON/XML-specific types\n- Supports reading/writing POCO classes\n- Supports reading/writing using DataContract, XmlSerialization, JsonName, attributes\n- Supports reading/writing using convention-based property renaming\n- Supports reading/writing C# 4.0 dynamic types\n- Supports reading/writing C# 3.0 Anonymous objects\n- Supports reading/writing LINQ queries\n- Supports custom reading/writing extensions \u0026 name resolution strategies\n- Dependency-injection-friendly for extremely flexible custom configurations\n- Stream-based serialization for reading/writing right off the wire\n- Provider allows automatic selection of serializer from Content-Type and Accept-Types HTTP headers\n\n### Basic Examples:\n\n#### Serialize to/from dynamic types (default for .NET 4.0):\n\tvar reader = new JsonReader(); var writer = new JsonWriter();\n\n\tstring input = @\"{ \"\"foo\"\": true, \"\"array\"\": [ 42, false, \"\"Hello!\"\", null ] }\";\n\tdynamic output = reader.Read(input);\n\tConsole.WriteLine(output.array[0]); // 42\n\tstring json = writer.Write(output);\n\tConsole.WriteLine(json); // {\"foo\":true,\"array\":[42,false,\"Hello!\",null]}\n\n#### Serialize to/from standard CLR types (default for .NET 2.0/3.5):\n\tstring input = @\"{ \"\"first\"\": \"\"Foo\"\", \"\"last\"\": \"\"Bar\"\" }\";\n\tvar output = reader.Read\u003cDictionary\u003cstring, object\u003e\u003e(input);\n\tConsole.WriteLine(output[\"first\"]); // Foo\n\toutput[\"middle\"] = \"Blah\";\n\tstring json = writer.Write(output);\n\tConsole.WriteLine(json); // {\"first\":\"Foo\",\"last\":\"Bar\",\"middle\":\"Blah\"}\n\n#### Serialize to/from Anonymous types\n\tstring input = @\"{ \"\"first\"\": \"\"Foo\"\", \"\"last\"\": \"\"Bar\"\" }\";\n\tvar template = new { first=String.Empty, middle=String.Empty, last=String.Empty };\n\tvar output = reader.Read(input, template);\n\tConsole.WriteLine(output.first); // Foo\n\toutput = new { output.first, middle=\"Blah\", output.last };\n\tstring json = writer.Write(output);\n\tConsole.WriteLine(json); // {\"first\":\"Foo\",\"middle\":\"Blah\",\"last\":\"Bar\"}\n\n#### Serialize to/from custom types and LINQ queries\n\n\t[DataContract]\n\tpublic class Person\n\t{\n\t\t[DataMember(Name=\"id\")] public long PersonID { get; set; }\n\t\t[DataMember(Name=\"first\")] public string FirstName { get; set; }\n\t\t[DataMember(Name=\"last\")] public string LastName { get; set; }\n\t}\n\n\t// respect DataContracts on the way in\n\tvar reader = new JsonReader(new DataReaderSettings(new DataContractResolverStrategy()));\n\t// use convention over configuration on the way out\n\tvar writer = new JsonWriter(new DataWriterSettings(new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.Lowercase, \"-\")));\n\n\tstring input =\n\t@\"[\n\t\t{ \"\"id\"\": 1, \"\"first\"\": \"\"Foo\"\", \"\"last\"\": \"\"Bar\"\" },\n\t\t{ \"\"id\"\": 2, \"\"first\"\": \"\"etc.\"\", \"\"last\"\": \"\"et al.\"\" },\n\t\t{ \"\"id\"\": 3, \"\"first\"\": \"\"Blah\"\", \"\"last\"\": \"\"Yada\"\" }\n\t]\";\n\n\tvar people = reader.Query\u003cPerson\u003e(input);\n\tvar query =\n\t\tfrom person in people.ArrayItems()\n\t\twhere person.PersonID == 1 || person.FirstName == \"Blah\"\n\t\torderby person.PersonID\n\t\tselect person;\n\n\tConsole.WriteLine(query.Last().LastName); // Yada\n\tstring json = writer.Write(query);\n\tConsole.WriteLine(json); // [{\"person-id\":1,\"first-name\":\"Foo\",\"last-name\":\"Bar\"},{\"person-id\":3,\"first-name\":\"Blah\",\"last-name\":\"Yada\"}]\n\n#### Serialize to/from TCP socket:\n\tTcpClient tcpClient = new TcpClient(server, port);\n\tNetworkStream tcpStream = tcpClient.GetStream();\n\n\t// read incrementally from incoming stream\n\tTextReader tcpReader = new StreamReader(tcpStream);\n\tFoo myFoo = new JsonReader.Read\u003cFoo\u003e(tcpReader);\n\n\t// write directly to output stream\n\tTextWriter tcpWriter = new StreamWriter(tcpStream);\n\tnew JsonWriter.Write(myFoo, tcpWriter);\n\n#### Fully customizable name resolution strategies\n\n\t// accept all variations! list in order of priority\n\tvar resolver = new CombinedResolverStrategy(\n\t\tnew JsonResolverStrategy(),   \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t// simple JSON attributes\n\t\tnew DataContractResolverStrategy(),   \t\t\t\t\t\t\t\t\t\t\t\t\t// DataContract attributes\n\t\tnew XmlResolverStrategy(),   \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t// XmlSerializer attributes\n\t\tnew ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.PascalCase),\t\t// DotNetStyle\n\t\tnew ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.CamelCase),\t\t// jsonStyle\n\t\tnew ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.Lowercase, \"-\"),\t// xml-style\n\t\tnew ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.Uppercase, \"_\"));\t// CONST_STYLE\n\n\t// pass the combined resolver strategy into the settings object\n\tvar reader = new JsonReader(new DataReaderSettings(resolver));\n\n\t// link the settings objects to share resolver strategies and name lookup cache\n\tvar writer = new JsonWriter(new DataWriterSettings(reader.Settings) { PrettyPrint=true });\n\n#### Build REST services using dependency injection to configure auto-serializer selection\n\n\t// setup once for the lifespan of the application\n\n\t// POCO name resolution, share lookups among all instances\n\tvar readerSettings = new DataReaderSettings();\t\t\t\t\n\tvar writerSettings = new DataWriterSettings(readerSettings);\n\n\tvar jsonReader = new JsonFx.Json.JsonReader(readerSettings);\n\tvar jsonWriter = new JsonFx.Json.JsonWriter(writerSettings);\n\n\tvar xmlReader = new JsonFx.Xml.XmlReader(readerSettings);\n\tvar xmlWriter = new JsonFx.Xml.XmlWriter(writerSettings);\n\n\t// list all the readers\n\tvar readerProvider = new DataReaderProvider(\n\t\tjsonReader,\n\t\txmlReader);\n\n\t// list all the writers\n\tvar writerProvider = new DataWriterProvider(\n\t\tjsonWriter,\n\t\txmlWriter);\n\n\t// ...later on a request comes in\n\n\t// incoming HTTP request headers\n\tstring contentTypeHeader = myRequest.Headers[HttpRequestHeader.ContentType];\n\tstring acceptHeader = myRequest.Headers[HttpRequestHeader.Accept];\n\n\tIDataReader deserializer = readerProvider.Find(contentTypeHeader);\n\n\tvar requestData;\n\tusing (var textReader = new StreamReader(myRequest.GetRequestStream()))\n\t{\n\t\trequestData = deserializer.Read(textReader);\n\t}\n\t\n\t// ...consume the data, generate a response\n\tvar myResponse = ...;\n\tvar responseData = ...;\n\n\tIDataWriter serializer = writerProvider.Find(acceptHeader, contentTypeHeader);\n\tusing (var textWriter = new StreamWriter(myResponse.GetResponseStream()))\n\t{\n\t\tserializer.Write(responseData);\n\t}\n\n  [1]: http://jsonfx.net\n  [2]: http://jsonfx.net/license\n  [3]: http://json.org\n  [4]: http://bsonspec.org\n  [5]: http://jsonml.org\n  ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsonfx%2Fjsonfx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsonfx%2Fjsonfx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsonfx%2Fjsonfx/lists"}