diff --git a/Doc/Samples/JsonPath/ErrorWhenNoMatchQuery.aml b/Doc/Samples/JsonPath/ErrorWhenNoMatchQuery.aml new file mode 100644 index 00000000..19cb3309 --- /dev/null +++ b/Doc/Samples/JsonPath/ErrorWhenNoMatchQuery.aml @@ -0,0 +1,14 @@ + + + + + This sample loads JSON and then queries values from it using Overload:Newtonsoft.Json.Linq.JToken.SelectToken. An error is thrown when part of the JSON path is not found. + +
+ Sample + + + +
+
+
\ No newline at end of file diff --git a/Doc/Samples/Linq/QueryJsonSelectToken.aml b/Doc/Samples/JsonPath/QueryJsonSelectToken.aml similarity index 88% rename from Doc/Samples/Linq/QueryJsonSelectToken.aml rename to Doc/Samples/JsonPath/QueryJsonSelectToken.aml index d11a6ea9..fd4d3185 100644 --- a/Doc/Samples/Linq/QueryJsonSelectToken.aml +++ b/Doc/Samples/JsonPath/QueryJsonSelectToken.aml @@ -7,7 +7,7 @@
Sample - +
diff --git a/Doc/Samples/Linq/QueryJsonSelectTokenEscaped.aml b/Doc/Samples/JsonPath/QueryJsonSelectTokenEscaped.aml similarity index 87% rename from Doc/Samples/Linq/QueryJsonSelectTokenEscaped.aml rename to Doc/Samples/JsonPath/QueryJsonSelectTokenEscaped.aml index c92645a9..5df1b0ef 100644 --- a/Doc/Samples/Linq/QueryJsonSelectTokenEscaped.aml +++ b/Doc/Samples/JsonPath/QueryJsonSelectTokenEscaped.aml @@ -7,7 +7,7 @@
Sample - +
diff --git a/Doc/Samples/Linq/QueryJsonSelectTokenJsonPath.aml b/Doc/Samples/JsonPath/QueryJsonSelectTokenJsonPath.aml similarity index 89% rename from Doc/Samples/Linq/QueryJsonSelectTokenJsonPath.aml rename to Doc/Samples/JsonPath/QueryJsonSelectTokenJsonPath.aml index f0b78163..31fe1365 100644 --- a/Doc/Samples/Linq/QueryJsonSelectTokenJsonPath.aml +++ b/Doc/Samples/JsonPath/QueryJsonSelectTokenJsonPath.aml @@ -11,7 +11,7 @@
Sample - +
diff --git a/Doc/Samples/Linq/QueryJsonSelectTokenWithLinq.aml b/Doc/Samples/JsonPath/QueryJsonSelectTokenWithLinq.aml similarity index 88% rename from Doc/Samples/Linq/QueryJsonSelectTokenWithLinq.aml rename to Doc/Samples/JsonPath/QueryJsonSelectTokenWithLinq.aml index 28b35420..f7fa1417 100644 --- a/Doc/Samples/Linq/QueryJsonSelectTokenWithLinq.aml +++ b/Doc/Samples/JsonPath/QueryJsonSelectTokenWithLinq.aml @@ -8,7 +8,7 @@
Sample - +
diff --git a/Doc/Samples/JsonPath/RegexQuery.aml b/Doc/Samples/JsonPath/RegexQuery.aml new file mode 100644 index 00000000..321c11a7 --- /dev/null +++ b/Doc/Samples/JsonPath/RegexQuery.aml @@ -0,0 +1,14 @@ + + + + + This sample loads JSON and then queries values from it using M:Newtonsoft.Json.Linq.JToken.SelectToken(System.String) with a regex JSON Path. + +
+ Sample + + + +
+
+
\ No newline at end of file diff --git a/Doc/Samples/JsonPath/StrictEqualsQuery.aml b/Doc/Samples/JsonPath/StrictEqualsQuery.aml new file mode 100644 index 00000000..f9faf052 --- /dev/null +++ b/Doc/Samples/JsonPath/StrictEqualsQuery.aml @@ -0,0 +1,14 @@ + + + + + This sample loads JSON and then queries values from it using M:Newtonsoft.Json.Linq.JToken.SelectToken(System.String) with a strict equals JSON Path. + +
+ Sample + + + +
+
+
\ No newline at end of file diff --git a/Doc/Samples/Serializer/CustomJsonConverterGeneric.aml b/Doc/Samples/Serializer/CustomJsonConverterGeneric.aml index 2829c22f..b9466177 100644 --- a/Doc/Samples/Serializer/CustomJsonConverterGeneric.aml +++ b/Doc/Samples/Serializer/CustomJsonConverterGeneric.aml @@ -2,8 +2,8 @@ - This sample creates a custom T:Newtonsoft.Json.JsonConverter{T} - that overrides serialization for the Version property with a custom display string. + This sample creates a custom converter from JsonConverter<T> + that overrides serialization for the Version class with a custom display string.
Sample diff --git a/Doc/SelectToken.aml b/Doc/SelectToken.aml index 17393001..9b8ce167 100644 --- a/Doc/SelectToken.aml +++ b/Doc/SelectToken.aml @@ -32,7 +32,7 @@ _blank . - +
diff --git a/Doc/doc.content b/Doc/doc.content index 466c8bb8..da88adea 100644 --- a/Doc/doc.content +++ b/Doc/doc.content @@ -29,7 +29,7 @@ - + @@ -63,7 +63,7 @@ - + @@ -96,7 +96,7 @@ - + @@ -114,10 +114,6 @@ - - - - @@ -136,6 +132,15 @@ + + + + + + + + + diff --git a/Doc/doc.shfbproj b/Doc/doc.shfbproj index 2c983b59..7edd1462 100644 --- a/Doc/doc.shfbproj +++ b/Doc/doc.shfbproj @@ -8,7 +8,7 @@ AnyCPU 2.0 {fd19f68e-72c8-4576-9775-b4480b0db686} - 2015.6.5.0 + 2017.9.26.0 Documentation @@ -20,7 +20,7 @@ Summary, Parameter, Returns, AutoDocumentCtors, Namespace, TypeParameter, AutoDocumentDispose - InheritedMembers, InheritedFrameworkMembers, Protected, SealedProtected, ProtectedInternalAsProtected + InheritedMembers, InheritedFrameworkMembers, Protected, SealedProtected, ProtectedInternalAsProtected, EditorBrowsableNever, NonBrowsable @@ -97,13 +97,19 @@ + + + + + + + - @@ -115,7 +121,6 @@ - @@ -142,8 +147,6 @@ - - @@ -272,6 +275,7 @@ + diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/ErrorWhenNoMatchQuery.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/ErrorWhenNoMatchQuery.cs new file mode 100644 index 00000000..4e7e53df --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/ErrorWhenNoMatchQuery.cs @@ -0,0 +1,76 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using Newtonsoft.Json.Linq; +#if DNXCORE50 +using Xunit; +using Test = Xunit.FactAttribute; +using Assert = Newtonsoft.Json.Tests.XUnitAssert; +#else +using NUnit.Framework; +#endif +using System; +using System.Collections.Generic; +#if NET20 +using Newtonsoft.Json.Utilities.LinqBridge; +#else +using System.Linq; +#endif +using System.Text; + +namespace Newtonsoft.Json.Tests.Documentation.Samples.JsonPath +{ + [TestFixture] + public class ErrorWhenNoMatchQuery : TestFixtureBase + { + [Test] + public void Example() + { + #region Usage + JArray items = JArray.Parse(@"[ + { + 'Name': 'John Doe', + }, + { + 'Name': 'Jane Doe', + } + ]"); + + // A true value for errorWhenNoMatch will result in an error if the queried value is missing + string result; + try + { + result = (string)items.SelectToken(@"$.[3]['Name']", errorWhenNoMatch: true); + } + catch (JsonException) + { + result = "Unable to find result in JSON."; + } + #endregion + + Assert.AreEqual("Unable to find result in JSON.", result); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectToken.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/QueryJsonSelectToken.cs similarity index 97% rename from Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectToken.cs rename to Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/QueryJsonSelectToken.cs index 9514505b..644dcf14 100644 --- a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectToken.cs +++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/QueryJsonSelectToken.cs @@ -41,7 +41,7 @@ using NUnit.Framework; #endif -namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq +namespace Newtonsoft.Json.Tests.Documentation.Samples.JsonPath { [TestFixture] public class QueryJsonSelectToken : TestFixtureBase diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectTokenEscaped.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/QueryJsonSelectTokenEscaped.cs similarity index 97% rename from Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectTokenEscaped.cs rename to Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/QueryJsonSelectTokenEscaped.cs index 8390c9e2..4322449b 100644 --- a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectTokenEscaped.cs +++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/QueryJsonSelectTokenEscaped.cs @@ -40,7 +40,7 @@ using System.Linq; #endif using System.Text; -namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq +namespace Newtonsoft.Json.Tests.Documentation.Samples.JsonPath { [TestFixture] public class QueryJsonSelectTokenEscaped : TestFixtureBase diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectTokenJsonPath.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/QueryJsonSelectTokenJsonPath.cs similarity index 98% rename from Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectTokenJsonPath.cs rename to Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/QueryJsonSelectTokenJsonPath.cs index ba548115..48656d80 100644 --- a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectTokenJsonPath.cs +++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/QueryJsonSelectTokenJsonPath.cs @@ -40,7 +40,7 @@ using System.Linq; #endif using System.Text; -namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq +namespace Newtonsoft.Json.Tests.Documentation.Samples.JsonPath { [TestFixture] public class QueryJsonSelectTokenJsonPath : TestFixtureBase diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectTokenWithLinq.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/QueryJsonSelectTokenWithLinq.cs similarity index 98% rename from Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectTokenWithLinq.cs rename to Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/QueryJsonSelectTokenWithLinq.cs index a71ad8b6..809f58d6 100644 --- a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectTokenWithLinq.cs +++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/QueryJsonSelectTokenWithLinq.cs @@ -41,7 +41,7 @@ using NUnit.Framework; #endif -namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq +namespace Newtonsoft.Json.Tests.Documentation.Samples.JsonPath { [TestFixture] public class QueryJsonSelectTokenWithLinq : TestFixtureBase diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/RegexQuery.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/RegexQuery.cs new file mode 100644 index 00000000..1264c348 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/RegexQuery.cs @@ -0,0 +1,79 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using Newtonsoft.Json.Linq; +#if DNXCORE50 +using Xunit; +using Test = Xunit.FactAttribute; +using Assert = Newtonsoft.Json.Tests.XUnitAssert; +#else +using NUnit.Framework; +#endif +using System; +using System.Collections.Generic; +#if NET20 +using Newtonsoft.Json.Utilities.LinqBridge; +#else +using System.Linq; +#endif +using System.Text; + +namespace Newtonsoft.Json.Tests.Documentation.Samples.JsonPath +{ + [TestFixture] + public class RegexQuery : TestFixtureBase + { + [Test] + public void Example() + { + #region Usage + JArray packages = JArray.Parse(@"[ + { + 'PackageId': 'Newtonsoft.Json', + 'Version': '11.0.1', + 'ReleaseDate': '2018-02-17T00:00:00' + }, + { + 'PackageId': 'NUnit', + 'Version': '3.9.0', + 'ReleaseDate': '2017-11-10T00:00:00' + } + ]"); + + // Find Newtonsoft packages + List newtonsoftPackages = packages.SelectTokens(@"$.[?(@.PackageId =~ /^Newtonsoft\.(.*)$/)]").ToList(); + + foreach (JToken item in newtonsoftPackages) + { + Console.WriteLine((string) item["PackageId"]); + } + // Newtonsoft.Json + #endregion + + Assert.AreEqual(1, newtonsoftPackages.Count); + Assert.AreEqual("Newtonsoft.Json", (string)newtonsoftPackages[0]["PackageId"]); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/StrictEqualsQuery.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/StrictEqualsQuery.cs new file mode 100644 index 00000000..2f7ddeee --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/JsonPath/StrictEqualsQuery.cs @@ -0,0 +1,76 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using Newtonsoft.Json.Linq; +#if DNXCORE50 +using Xunit; +using Test = Xunit.FactAttribute; +using Assert = Newtonsoft.Json.Tests.XUnitAssert; +#else +using NUnit.Framework; +#endif +using System; +using System.Collections.Generic; +#if NET20 +using Newtonsoft.Json.Utilities.LinqBridge; +#else +using System.Linq; +#endif +using System.Text; + +namespace Newtonsoft.Json.Tests.Documentation.Samples.JsonPath +{ + [TestFixture] + public class StrictEqualsQuery : TestFixtureBase + { + [Test] + public void Example() + { + #region Usage + JArray items = JArray.Parse(@"[ + { + 'Name': 'Valid JSON', + 'Valid': true + }, + { + 'Name': 'Invalid JSON', + 'Valid': 'true' + } + ]"); + + // Use === operator. Compared types must be the same to be valid + List strictResults = items.SelectTokens(@"$.[?(@.Valid === true)]").ToList(); + + foreach (JToken item in strictResults) + { + Console.WriteLine((string)item["Name"]); + } + // Valid JSON + #endregion + + Assert.AreEqual(1, strictResults.Count); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonIgnoreCase.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonIgnoreCase.cs new file mode 100644 index 00000000..323b4a35 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonIgnoreCase.cs @@ -0,0 +1,66 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +#if NET20 +using Newtonsoft.Json.Utilities.LinqBridge; +#else +using System.Linq; +#endif +using System.Text; +#if DNXCORE50 +using Xunit; +using Test = Xunit.FactAttribute; +using Assert = Newtonsoft.Json.Tests.XUnitAssert; +#else +using NUnit.Framework; +#endif + +namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq +{ + [TestFixture] + public class QueryJsonIgnoreCase : TestFixtureBase + { + [Test] + public void Example() + { + #region Usage + string json = @"{ + 'name': 'James Newton-King', + 'blog': 'http://james.newtonking.com' + }"; + + JObject profile = JObject.Parse(json); + + string name = (string)profile.GetValue("Name", StringComparison.OrdinalIgnoreCase); + Console.WriteLine(name); + #endregion + + Assert.AreEqual("James Newton-King", name); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json/DefaultJsonNameTable.cs b/Src/Newtonsoft.Json/DefaultJsonNameTable.cs index 10f2cc94..4b9618a9 100644 --- a/Src/Newtonsoft.Json/DefaultJsonNameTable.cs +++ b/Src/Newtonsoft.Json/DefaultJsonNameTable.cs @@ -53,11 +53,12 @@ namespace Newtonsoft.Json } /// - /// Gets the string containing the same characters as the specified range of characters in the given array. + /// Gets a string containing the same characters as the specified range of characters in the given array. /// /// The character array containing the name to find. /// The zero-based index into the array specifying the first character of the name. /// The number of characters in the name. + /// A string containing the same characters as the specified range of characters in the given array. public override string Get(char[] key, int start, int length) { if (length == 0) @@ -96,6 +97,7 @@ namespace Newtonsoft.Json /// /// The string to add. /// This method is not thread-safe. + /// The resolved string. public string Add(string key) { if (key == null) diff --git a/Src/Newtonsoft.Json/JsonNameTable.cs b/Src/Newtonsoft.Json/JsonNameTable.cs index 22888ae5..b7937618 100644 --- a/Src/Newtonsoft.Json/JsonNameTable.cs +++ b/Src/Newtonsoft.Json/JsonNameTable.cs @@ -6,11 +6,12 @@ public abstract class JsonNameTable { /// - /// Gets the string containing the same characters as the specified range of characters in the given array. + /// Gets a string containing the same characters as the specified range of characters in the given array. /// /// The character array containing the name to find. /// The zero-based index into the array specifying the first character of the name. /// The number of characters in the name. + /// A string containing the same characters as the specified range of characters in the given array. public abstract string Get(char[] key, int start, int length); } }