diff --git a/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs b/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs
index 89a6806d..7ca9d6e3 100644
--- a/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs
+++ b/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs
@@ -2,6 +2,7 @@
using System.Linq.Dynamic.Core.NewtonsoftJson.Config;
using System.Linq.Dynamic.Core.NewtonsoftJson.Extensions;
using System.Linq.Dynamic.Core.Validation;
+using JetBrains.Annotations;
using Newtonsoft.Json.Linq;
namespace System.Linq.Dynamic.Core.NewtonsoftJson;
@@ -303,6 +304,42 @@ public static JToken First(this JArray source, string predicate, params object?[
}
#endregion FirstOrDefault
+ #region GroupBy
+ ///
+ /// Groups the elements of a sequence according to a specified key string function
+ /// and creates a result value from each group and its key.
+ ///
+ /// A whose elements to group.
+ /// A string expression to specify the key for each element.
+ /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings.
+ /// A where each element represents a projection over a group and its key.
+ [PublicAPI]
+ public static JArray GroupBy(this JArray source, string keySelector, params object[]? args)
+ {
+ return GroupBy(source, NewtonsoftJsonParsingConfig.Default, keySelector, args);
+ }
+
+ ///
+ /// Groups the elements of a sequence according to a specified key string function
+ /// and creates a result value from each group and its key.
+ ///
+ /// A whose elements to group.
+ /// The .
+ /// A string expression to specify the key for each element.
+ /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings.
+ /// A where each element represents a projection over a group and its key.
+ [PublicAPI]
+ public static JArray GroupBy(this JArray source, NewtonsoftJsonParsingConfig config, string keySelector, params object[]? args)
+ {
+ Check.NotNull(source);
+ Check.NotNull(config);
+ Check.NotNullOrEmpty(keySelector);
+
+ var queryable = ToQueryable(source, config);
+ return ToJArray(() => queryable.GroupBy(config, keySelector, args));
+ }
+ #endregion
+
#region Last
///
/// Returns the last element of a sequence that satisfies a specified condition.
@@ -813,7 +850,17 @@ private static JArray ToJArray(Func func)
var array = new JArray();
foreach (var dynamicElement in func())
{
- var element = dynamicElement is DynamicClass dynamicClass ? JObject.FromObject(dynamicClass) : dynamicElement;
+ var element = dynamicElement switch
+ {
+ IGrouping