using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public static void Test()
Test("{'grandparent': { 'parent' : {'object' : 'value'}}}", "..object");
Test("{'grandparent': [{'object' : 'value'}]}", "..object");
static void Test(string input, string query)
Console.WriteLine("\nTesting JSON \"{0}\" using query \"{1}\"", input, query);
var jsonInput = JObject.Parse(input);
var jsonObject = jsonInput.SelectToken(query);
var path = jsonObject.Path;
var parentPath = jsonObject.SelectableParent().Path;
Console.WriteLine(parentPath);
Assert.IsTrue(path != parentPath);
public static partial class JsonExtensions
public static JToken SelectableParent(this JToken token)
var parent = token.Parent;
public static void Main()
Console.WriteLine("Environment version: " + Environment.Version);
Console.WriteLine("Json.NET version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");