using System.Runtime.Serialization;
using System.Globalization;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
""@encoding"" : ""UTF-8""
""@FeedName"" : ""content"",
""now"" : ""2016-10-17T14:11:38.00"",
""@statusType"" : ""Published"",
""@isReleased"" : ""Yes"",
""@productCategory"" : ""Issuer"",
""@PrimarySymbol"" : ""GOOGL"",
""@SecondarySymbol"" : ""Google"",
""@lastVersion"" : ""true"",
""@lastPublished"" : ""true"",
""#cdata-section"" : ""https://aaa.yyy.com/docs/xml/708893eb-1fd9-4278-8b0e-e7e0738d8105.xml""
""#cdata-section"" : ""https://aaa.yyy.com/docs/html/708893eb-1fd9-4278-8b0e-e7e0738d8105.html""
""#cdata-section"" : ""https://aaa.yyy.com/docs/pdf/708893eb-1fd9-4278-8b0e-e7e0738d8105.pdf""
""@type"" : ""ALTERNATE PDF"",
""#cdata-section"" : ""https://aaa.yyy.com/docs/shortPdf/708893eb-1fd9-4278-8b0e-e7e0738d8105.pdf""
""@statusType"" : ""Published"",
""@isReleased"" : ""Yes"",
""@productCategory"" : ""Issuer"",
""@PrimarySymbol"" : ""AAPL"",
""@SecondarySymbol"" : ""Apple"",
""@lastVersion"" : ""false"",
""@lastPublished"" : ""false"",
""#cdata-section"" : ""https://aaa.yyy.com/docs/version/708893eb-1fd9-4278-8b0e-e7e0738d8105.1476742297.xml""
""#cdata-section"" : ""https://aaa.yyy.com/docs/version/708893eb-1fd9-4278-8b0e-e7e0738d8105.1476742297.html""
""#cdata-section"" : ""https://aaa.yyy.com/docs/version/708893eb-1fd9-4278-8b0e-e7e0738d8105.1476742297.pdf""
""@type"" : ""ALTERNATE PDF"",
""#cdata-section"" : ""https://aaa.yyy.com/docs/version/708893eb-1fd9-4278-8b0e-e7e0738d8105.1476742297_short.pdf""
""@lastVersion"" : ""true"",
""@lastPublished"" : ""true"",
""#cdata-section"" : ""https://aaa.yyy.com/docs/xml/708893eb-1fd9-4278-8b0e-e7e0738d8105.xml""
""#cdata-section"" : ""https://aaa.yyy.com/docs/html/708893eb-1fd9-4278-8b0e-e7e0738d8105.html""
""#cdata-section"" : ""https://aaa.yyy.com/docs/pdf/708893eb-1fd9-4278-8b0e-e7e0738d8105.pdf""
""@type"" : ""ALTERNATE PDF"",
""#cdata-section"" : ""https://aaa.yyy.com/docs/version/708893eb-1fd9-4278-8b0e-e7e0738d8105.1577742297_short.pdf""
""@statusType"" : ""Published"",
""@isReleased"" : ""Yes"",
""@productCategory"" : ""Issuer"",
""@PrimarySymbol"" : ""AAA"",
""@SecondarySymbol"" : ""Some name 1"",
""@PrimarySymbol"" : ""ABC"",
""@SecondarySymbol"" : ""Some Name 2"",
""@PrimarySymbol"" : ""BBB"",
""@SecondarySymbol"" : ""Some Name 3"",
""@PrimarySymbol"" : ""CCC"",
""@SecondarySymbol"" : ""Some Name 4"",
""@lastVersion"" : ""true"",
""@lastPublished"" : ""true"",
""#cdata-section"" : ""https://aaa.yyy.com/docs/xml/1c420081-0ce5-4959-91d3-848bbbccd3e3.xml""
""#cdata-section"" : ""https://aaa.yyy.com/docs/html/1c420081-0ce5-4959-91d3-848bbbccd3e3.html""
""#cdata-section"" : ""https://aaa.yyy.com/docs/pdf/1c420081-0ce5-4959-91d3-848bbbccd3e3.pdf""
""@type"" : ""ALTERNATE PDF"",
""#cdata-section"" : ""https://aaa.yyy.com/docs/shortPdf/1c420081-0ce5-4959-91d3-848bbbccd3e3.pdf""
internal static void Test()
var jsonFeed = JToken.Parse(GetJson());
private static void TestFullQuery(JToken jsonFeed)
string pdfUrlType = "PDF";
(from content in jsonFeed.SelectTokens("DataFeed.Content").SelectMany(i => i.ObjectsOrSelf())
.SelectToken("ContentData.ProductStatus.@productCategory")
where issuer.FirstOrDefault().Equals("Issuer")
let symbol = (string)content.SelectToken("ContentData.ProductStatus.Symbol.@PrimarySymbol")
let lastContentVersion = content
.SelectToken("ContentData.ContentVersion")
.Where(v => (bool?)v.SelectToken("@lastVersion") == true)
where lastContentVersion != null
let pdfUrl = lastContentVersion.SelectToken("Url")
.Where(u => (string)u.SelectToken("@type") == pdfUrlType)
DocID = (string)content.SelectToken("ContentData.@docId"),
BMId = (int?)content.SelectToken("ContentData.ProductStatus.Symbol.@BmId"),
PDFUrl = (string)pdfUrl.SelectToken("#cdata-section")
Console.WriteLine(JsonConvert.SerializeObject(query, Formatting.Indented));
public static class JsonExtensions
public static IEnumerable<JToken> SingleOrMultiple(this JToken source)
IEnumerable<JToken> arr = source as JArray;
return arr ?? new[] { source };
public static IEnumerable<JToken> DescendantsAndSelf(this JToken node)
return Enumerable.Empty<JToken>();
var container = node as JContainer;
return container.DescendantsAndSelf();
public static IEnumerable<JObject> ObjectsOrSelf(this JToken root)
yield return (JObject)root;
else if (root is JContainer)
foreach (var item in ((JContainer)root).Children())
foreach (var child in item.ObjectsOrSelf())
public static void Main()
Console.WriteLine("Json.NET version: " + typeof(JsonSerializer).Assembly.FullName);