using System.Collections;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
using System.Text.Json.Nodes;
public static void Test()
public static void TestTextValue()
string jsonText = GetJson();
var rootJsonNode = JsonNode.Parse(jsonText);
var path = JsonPath.Parse("$..textValue");
var results = path.Evaluate(rootJsonNode);
var newArray = JsonSerializer.SerializeToNode(results.Matches.Select(m => m.Value))!.AsArray();
Console.WriteLine(JsonSerializer.Serialize(newArray));
Assert.That(JsonNode.DeepEquals(newArray, JsonNode.Parse(expectedJson)));
public static void TestNumValue()
var root = JsonNode.Parse(GetJson());
var path = JsonPath.Parse("$..numValue");
var results = path.Evaluate(root);
var newArray = JsonSerializer.SerializeToNode(results.Matches.Select(m => m.Value))!.AsArray();
Console.WriteLine(JsonSerializer.Serialize(newArray));
Assert.That(JsonNode.DeepEquals(newArray, JsonNode.Parse(expectedJson)));
static string GetJson() =>
public static void Main()
Console.WriteLine("Environment version: {0} ({1}), {2}", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , Environment.Version, Environment.OSVersion);
Console.WriteLine("System.Text.Json version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("JsonPath.Net version: " + typeof(Json.Path.JsonPath).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");