Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting issue in the length property of JSONPATH #21

Open
RiteshKo opened this issue Jun 15, 2022 · 1 comment
Open

Getting issue in the length property of JSONPATH #21

RiteshKo opened this issue Jun 15, 2022 · 1 comment
Labels
question Further information is requested

Comments

@RiteshKo
Copy link

RiteshKo commented Jun 15, 2022

Below is my json string

[{"Id":1,"Name":"first value","Added":"2022-06-15T09:48:36.7132436Z"},{"Id":2,"Name":"second value","Added":"2022-06-15T09:48:36.7132479Z"},{"Id":3,"Name":"third value","Added":"2022-06-15T09:48:36.713248Z"}]

And the structure is:

public class Data
{
    public int Id { get; set; }
    public string Name { get; set; }
    public DateTime Added { get; set; }
}

In the redis, I have one key for which I am storing List.
In case to insert a single data record I was using length to store new data record and was using JSONPATH.

Below is the JSONPATH
var serializedRedisData = JsonConvert.SerializeObject(data);
_database.JsonSet(redisKey, serializedRedisData, ".[(@.length)]");

But getting below error:

StackExchange.Redis.RedisServerException: 'JSON Path error: path error: \n$.[(@.length)]\n^^^^^\n'

@tombatron
Copy link
Owner

I think the issue here is that in order to append to an existing array you need to call _database.JsonArrayAppend or _database.JsonArrayAppendAsync.

After you have that, then you could use _database.JsonGet with the JSONPath $.[?(@.Id==5)] (or whatever Id) to retrieve the item.

@tombatron tombatron added the question Further information is requested label Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants