├── .gitignore
├── license.txt
├── readme.md
└── src
├── Jsonite.Benchmarks
├── App.config
├── BenchGenericDeserialize.cs
├── Jsonite.Benchmarks.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── packages.config
├── results
│ └── JsonResults.xlsx
└── test.json
├── Jsonite.Tests
├── App.config
├── Jsonite.Tests.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── TestFiles
│ ├── 000-test-error-false1.out.txt
│ ├── 000-test-error-false1.txt
│ ├── 000-test-error-null1.out.txt
│ ├── 000-test-error-null1.txt
│ ├── 000-test-error-true1.out.txt
│ ├── 000-test-error-true1.txt
│ ├── 000-test-error-true2.out.txt
│ ├── 000-test-error-true2.txt
│ ├── 001-test-error-string1.out.txt
│ ├── 001-test-error-string1.txt
│ ├── 001-test-error-string2.out.txt
│ ├── 001-test-error-string2.txt
│ ├── 001-test-error-string3.out.txt
│ ├── 001-test-error-string3.txt
│ ├── 001-test-error-string4.out.txt
│ ├── 001-test-error-string4.txt
│ ├── 002-test-error-number1.out.txt
│ ├── 002-test-error-number1.txt
│ ├── 002-test-error-number2.out.txt
│ ├── 002-test-error-number2.txt
│ ├── 002-test-error-number3.out.txt
│ ├── 002-test-error-number3.txt
│ ├── 002-test-error-number4.out.txt
│ ├── 002-test-error-number4.txt
│ ├── 020-test-error-object1.out.txt
│ ├── 020-test-error-object1.txt
│ ├── 020-test-error-object2.out.txt
│ ├── 020-test-error-object2.txt
│ ├── 020-test-error-object3.out.txt
│ ├── 020-test-error-object3.txt
│ ├── 020-test-error-object4.out.txt
│ ├── 020-test-error-object4.txt
│ ├── 020-test-error-object5.out.txt
│ ├── 020-test-error-object5.txt
│ ├── 030-test-error-array1.out.txt
│ ├── 030-test-error-array1.txt
│ ├── 030-test-error-array2.out.txt
│ ├── 030-test-error-array2.txt
│ ├── 030-test-error-array3.out.txt
│ └── 030-test-error-array3.txt
├── TestParser.cs
├── TextAssert.cs
└── packages.config
├── Jsonite
├── Jsonite.cs
└── Jsonite.csproj
├── Textamina.Jsonite.sln.DotSettings
└── jsonite.sln
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | build/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opensdf
80 | *.sdf
81 | *.cachefile
82 |
83 | # Visual Studio profiler
84 | *.psess
85 | *.vsp
86 | *.vspx
87 |
88 | # TFS 2012 Local Workspace
89 | $tf/
90 |
91 | # Guidance Automation Toolkit
92 | *.gpState
93 |
94 | # ReSharper is a .NET coding add-in
95 | _ReSharper*/
96 | *.[Rr]e[Ss]harper
97 | *.DotSettings.user
98 |
99 | # JustCode is a .NET coding add-in
100 | .JustCode
101 |
102 | # TeamCity is a build add-in
103 | _TeamCity*
104 |
105 | # DotCover is a Code Coverage Tool
106 | *.dotCover
107 |
108 | # NCrunch
109 | _NCrunch_*
110 | .*crunch*.local.xml
111 | nCrunchTemp_*
112 |
113 | # MightyMoose
114 | *.mm.*
115 | AutoTest.Net/
116 |
117 | # Web workbench (sass)
118 | .sass-cache/
119 |
120 | # Installshield output folder
121 | [Ee]xpress/
122 |
123 | # DocProject is a documentation generator add-in
124 | DocProject/buildhelp/
125 | DocProject/Help/*.HxT
126 | DocProject/Help/*.HxC
127 | DocProject/Help/*.hhc
128 | DocProject/Help/*.hhk
129 | DocProject/Help/*.hhp
130 | DocProject/Help/Html2
131 | DocProject/Help/html
132 |
133 | # Click-Once directory
134 | publish/
135 |
136 | # Publish Web Output
137 | *.[Pp]ublish.xml
138 | *.azurePubxml
139 | # TODO: Comment the next line if you want to checkin your web deploy settings
140 | # but database connection strings (with potential passwords) will be unencrypted
141 | *.pubxml
142 | *.publishproj
143 |
144 | # NuGet Packages
145 | *.nupkg
146 | # The packages folder can be ignored because of Package Restore
147 | **/packages/*
148 | # except build/, which is used as an MSBuild target.
149 | !**/packages/build/
150 | # Uncomment if necessary however generally it will be regenerated when needed
151 | #!**/packages/repositories.config
152 |
153 | # Windows Azure Build Output
154 | csx/
155 | *.build.csdef
156 |
157 | # Windows Store app package directory
158 | AppPackages/
159 |
160 | # Visual Studio cache files
161 | # files ending in .cache can be ignored
162 | *.[Cc]ache
163 | # but keep track of directories ending in .cache
164 | !*.[Cc]ache/
165 |
166 | # Others
167 | ClientBin/
168 | [Ss]tyle[Cc]op.*
169 | ~$*
170 | *~
171 | *.dbmdl
172 | *.dbproj.schemaview
173 | *.pfx
174 | *.publishsettings
175 | node_modules/
176 | orleans.codegen.cs
177 |
178 | # RIA/Silverlight projects
179 | Generated_Code/
180 |
181 | # Backup & report files from converting an old project file
182 | # to a newer Visual Studio version. Backup files are not needed,
183 | # because we have git ;-)
184 | _UpgradeReport_Files/
185 | Backup*/
186 | UpgradeLog*.XML
187 | UpgradeLog*.htm
188 |
189 | # SQL Server files
190 | *.mdf
191 | *.ldf
192 |
193 | # Business Intelligence projects
194 | *.rdl.data
195 | *.bim.layout
196 | *.bim_*.settings
197 |
198 | # Microsoft Fakes
199 | FakesAssemblies/
200 |
201 | # Node.js Tools for Visual Studio
202 | .ntvs_analysis.dat
203 |
204 | # Visual Studio 6 build log
205 | *.plg
206 |
207 | # Visual Studio 6 workspace options file
208 | *.opt
209 |
210 | # Visual Studio LightSwitch build output
211 | **/*.HTMLClient/GeneratedArtifacts
212 | **/*.DesktopClient/GeneratedArtifacts
213 | **/*.DesktopClient/ModelManifest.xml
214 | **/*.Server/GeneratedArtifacts
215 | **/*.Server/ModelManifest.xml
216 | _Pvt_Extensions
217 |
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016, Alexandre Mutel
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification
5 | , are permitted provided that the following conditions are met:
6 |
7 | 1. Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | 2. Redistributions in binary form must reproduce the above copyright notice,
11 | this list of conditions and the following disclaimer in the documentation
12 | and/or other materials provided with the distribution.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # jsonite
2 |
3 | Jsonite is a lightweight JSON serializer and deserializer for .NET
4 |
5 | ```C#
6 | var obj = (JsonObject)Json.Deserialize(@"{""name"": ""John"", ""age"": 26}")
7 | ```
8 |
9 | Jsonite provides the following features:
10 |
11 | - The implementation *should be* [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf) and [RFC 4627](https://tools.ietf.org/html/rfc4627) compliant. If you find any issues please log an issue!
12 | - Single file serializer/deserializer that can be embedded directly into a project.
13 | - Default implementation serializing/deserializing from/to `JsonObject` / `JsonArray`
14 | - Method `Json.Validate` to validate a json object
15 | - Precise error with line/column when deserializing an invalid json text.
16 | - Very fast and very low GC memory pressure when deserializing/serializing compare to other JSON libraries.
17 | - Simple pluggable API to allow to deserialize/serialize from/to other kinds of .NET objects (through the `JsonReflector` class)
18 | - Default implementation does not use Reflection or Expression to serialize/deserialize to .NET `JsonObject`/`JsonArray`.
19 |
20 | Jsonite is easily embeddable for quickly decoding/encoding JSON without relying on an external Json library.
21 |
22 | ## Usage and Compilation
23 |
24 | As this library is intended to be embedded and compiled directly from your project, we don't provide a nuget package.
25 |
26 | Instead, you can for example use this repository as a git sub-module of your project and reference directly the file [`Jsonite.cs`](https://github.com/xoofx/jsonite/blob/master/src/Jsonite/Jsonite.cs)
27 |
28 | The code is compatible with `PCL .NET 4.5+`, `CoreCLR`, `CoreRT` and `UWP10`.
29 |
30 | ## Limitations
31 |
32 | Jsonite does not provide a deserializer/serializer from/to an arbitrary object graph. Prefers using a more complete solution like Json.NET.
33 |
34 | ## License
35 | This software is released under the [BSD-Clause 2 license](http://opensource.org/licenses/BSD-2-Clause).
36 |
37 | ## Author
38 |
39 | Alexandre Mutel aka [xoofx](http://xoofx.com).
40 |
--------------------------------------------------------------------------------
/src/Jsonite.Benchmarks/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/Jsonite.Benchmarks/BenchGenericDeserialize.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.IO;
3 | using BenchmarkDotNet;
4 | using BenchmarkDotNet.Attributes;
5 |
6 | namespace Jsonite.Benchmarks
7 | {
8 | public class BenchGenericDeserialize
9 | {
10 | private readonly string testJson;
11 |
12 | public BenchGenericDeserialize()
13 | {
14 | testJson = File.ReadAllText("test.json");
15 | }
16 |
17 | [Benchmark(Description = "Textamina.Jsonite")]
18 | public void TestJsonite()
19 | {
20 | var result = Json.Deserialize(testJson);
21 | }
22 |
23 | [Benchmark(Description = "Newtonsoft.Json")]
24 | public void TestNewtonsoftJson()
25 | {
26 | var result = Newtonsoft.Json.JsonConvert.DeserializeObject>(testJson);
27 | }
28 |
29 | [Benchmark(Description = "System.Text.Json (FastJsonParser)")]
30 | public void TestSystemTextJson()
31 | {
32 | var parser = new System.Text.Json.JsonParser();
33 | var result = parser.Parse>(testJson);
34 | }
35 |
36 | [Benchmark(Description = "ServiceStack.Text")]
37 | public void TestServiceStackText()
38 | {
39 | // Force ServiceStack.Text to deserialize completely the object (otherwise it is deserializing only the first object level, which is not what we want to test here)
40 | ServiceStack.Text.JsConfig.ConvertObjectTypesIntoStringDictionary = true;
41 | var result = (Dictionary)ServiceStack.StringExtensions.FromJson