Filter JObject

Hi, I’m trying to filter a JObject the same way I do with JArrays, but for some reason it won’t let me, as it Throws the error “Cannot access child value on Newtonsoft.Json.Linq.JValue”.

In the “Assign” activity, right box, I have this logic:

New JObject(jObjectTransactions("prices").Where(Function (f) (
	(DateTime.Now - DateTime.ParseExact(
		f(0)(0).ToString.Replace("01: +0", String.Empty).Trim,
		"MMM dd yyyy",
		System.Globalization.CultureInfo.InvariantCulture
	)).Days < 30
)))

The logic is simple, the JObject contains dates at the level “jObjectTransactions(“prices”)(0)(0)”, so what I’m doing is parsing those dates from String to DateTime to compare and keep only the ones that are not older than 30 days.

At the left side of the panel, I have the same variable “jObjectTransactions”, to which I’m trying to assign the filtered JObject.

image

Does anyone knows how to achieve what I want?. I would really appreciate it.

Here is the full Json:
Json.txt (1.7 KB)

May we ask you to share with us the entire JSON (preferred as text file)

thanks

Done. I edited my question and uploaded the txt with the Json inside.

find some little prototype here:

myJObject("prices").Where(Function (x) (Now.Date - Cdate(x(0).Value(Of String).Substring(0,11)).Date).TotalDays < 220).tolist

Feel free to port it to LINQ Query Syntax. Also check the needed difference logic now-Date or date-now and the threshold (30). We used another one as sample data did not cover such date s and would result to empty filter result

1 Like

Why is it returning a List?. I need the same JObject, but filtered.

Also I don’t know exactly what you mean by “porting it to LINQ Query Syntax”. I’m really not that well versed in this matter.

Let us summarize - prototype samples do demonstrate on how to access and handle the date from the array items

you can adapt by your needs

could maybe caused by the second (0) from | as you want to access the first array element

Your json value of price is a
grafik
grafik
A jarray where the array items again are an array
But not a JObject

Also more important. The return from LINQ Where Operator is of Enumerable or else when specify it , e.g. with the ToXXX Method

Thank you, the output from your example has the info I need.

I was able to adapt your example to be able to specify the format for the DateTime, and it is working:

jObjectTransactions("prices").Where(Function (f) (
	DateTime.Now - DateTime.ParseExact(
		f(0).Value(Of String).Substring(0,11).Replace("01: +0", String.Empty).Trim,
		"MMM dd yyyy",
		System.Globalization.CultureInfo.InvariantCulture
	)).Days < 30
).ToList

Just 1 question, How does this part works?. Because I have no Idea.

f(0).Value(Of String).Substring(0,11)

Thank you

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.