Questions tagged [linq-to-json]

An API to work with JSON objects.

Linq to JSON is part of the Newtonsoft.Json.Linq Namespace. It has been designed to with Linq to enable the querying and creation of JSON objects easily.

38 questions
57
votes
4 answers

Can I LINQ a JSON?

This is the JSON I get from a request on .NET: { "id": "110355660738", "picture": { "data": { "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/1027085_12033235063_5234302342947_n.jpg", "is_silhouette": false } …
markzzz
  • 47,390
  • 120
  • 299
  • 507
16
votes
1 answer

Why is there a JConstructor?

Json.NET defines a JConstructor type. This is confusing, because (to the best of my knowledge) constructors are not part of JSON. I double-checked the JSON spec and browsed json.org but couldn't find anything. There also doesn't seem to be much…
smartcaveman
  • 41,281
  • 29
  • 127
  • 212
6
votes
2 answers

JArray.Remove(JToken) does not delete

I have a JObject with a JSON like it: {"name" : "user1", "groups" : ["group 1", "group2"]} I would like to delete one group by the name. So I have a code like this: JObject userJson = JObject.Parse(user); JArray groups = userJson["groups"] as…
ronald.js.cr
  • 81
  • 1
  • 1
  • 2
6
votes
4 answers

LINQ to JSON - Setup list from dynamic nested array

Here's the json string that I have. { "?xml" : { "@version" : "1.0", "@encoding" : "UTF-8" }, "DataFeed" : { "@FeedName" : "issuerDetails", "SecurityDetails" : { "Security" : { …
inquisitive_one
  • 1,465
  • 7
  • 32
  • 56
4
votes
3 answers

LINQ to JSON - Query for object or an array

I'm trying to get a list of SEDOL's & ADP values. Below is my json text: { "DataFeed" : { "@FeedName" : "AdminData", "Issuer" : [{ "id" : "1528", "name" : "ZYZ.A a Test Company", …
inquisitive_one
  • 1,465
  • 7
  • 32
  • 56
3
votes
2 answers

Json.NET decimal precision loss

I have an issue with deserializing decimal value. JObject.Parse("{\"available\":8777.831438322572000}") If I type this code in VS under debugger the result is "available": 8777.8314383225716 If I try this obj.Value("available") the…
Alew
  • 316
  • 4
  • 12
3
votes
1 answer

Convert List To JObject

Consider this code: var joWork = ((JObject) x).Properties() .Where(p => p.Value.Type == JTokenType.String).ToList(); I end up with a List. Is there a quick way using Linq or a JSON.NET function to convert that List object…
Jazimov
  • 12,626
  • 9
  • 52
  • 59
3
votes
1 answer

Why does dumping this JObject throw an AmbiguousMatchException in LINQPad?

When I run this code in LINQPad using JSON.NET: var x = JObject.Parse( @"{ ""data"" : [ { ""id"" : ""bbab529ecefe58569c2b301a"", ""name"" : ""Sample Name"", ""group"" : ""8b618be8dc064e653daf62f9"", ""description"" : ""Sample…
Hydrargyrum
  • 3,378
  • 4
  • 27
  • 41
2
votes
2 answers

Need to run LINQ queries on several hundred JSON files in child folders

Using c#: I have a few hundreds of JSON files in nested folders in file system. I need to run LINQ queries within the data in files and find the JSON files that their JSON data matches certain crieria. I can simly serialize all the JSON files in a…
Allan Xu
  • 7,998
  • 11
  • 51
  • 122
2
votes
1 answer

LINQ to JSON - Select array object element where specific property matches

MY LINQ-Fu skills pretty bad and after looking at JSON.NET examples I am still having trouble figuring out how to select that data I am after. I have a blob of JSON as follows ... { "@odata.context":…
webworm
  • 10,587
  • 33
  • 120
  • 217
1
vote
3 answers

Newtonsoft json access array inside json

I have a json file like this: { "foo": "bar", "1": 0, "array": [ "foo", "bar" ] } and I can access "foo" and "1" like this: using Newtonsoft.Json JObject o = JObject.Parse(json) Console.WriteLine((string)o["foo"]) // prints…
Neins
  • 121
  • 5
1
vote
1 answer

C# Parse a dynamic JSON JToken to a List

Can we parse a dynamic JSON to a List of Object List public class DiffModel { public string Property { get; set; } public string OldValue { get; set; } public string NewValue { get; set; } } The JSON is generated with the help…
Sebastian
  • 4,625
  • 17
  • 76
  • 145
1
vote
1 answer

How to use SelectToken with square brackets?

How can I get the value or make a SelectToken, if the Name of the JToken includes square brackets? tmpJToken.Value(Of String)("3/32[v]") or tmpJToken.SelectToken("3/32[v]") Do I have to escape the square brackets? The JSON looks…
Mec-Eng
  • 199
  • 10
1
vote
4 answers

How to query into a JSON getting using LINQ?

JSON { "count": 3, "value": [ { "id": "AAAAAAAAAAAAA", "description": "test1", "name": "name1" }, { "id": "BBBBBBBBBB", "description": "test2", "name": "name2" }, { "id":…
Hexxed
  • 683
  • 1
  • 10
  • 28
1
vote
1 answer

Linq-to-JSON SelectToken Method Confusion and Alternatives

I hope I can ask this question without provide a code sample because it's more about missing documentation and potential alternative methods/commands. In my existing Linq-to-JSON code, I have this snippet: var firstOrDefault =…
Jazimov
  • 12,626
  • 9
  • 52
  • 59
1
2 3