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

JMESPath slices and pre-computed runtime expressions #1510

Merged
merged 10 commits into from
Dec 18, 2024
Merged

Conversation

stephenberry
Copy link
Owner

@stephenberry stephenberry commented Dec 17, 2024

Adds slice support for glz::read_jmespath:

std::vector<int> data{0,1,2,3,4,5,6,7,8,9};
std::string buffer{};
expect(not glz::write_json(data, buffer));

std::vector<int> slice{};
expect(not glz::read_jmespath<"[0:5]">(slice, buffer));
expect(slice.size() == 5);
expect(slice[0] == 0);
expect(slice[1] == 1);
expect(slice[2] == 2);
expect(slice[3] == 3);
expect(slice[4] == 4);

The run-time version of glz::read_jmespath also now takes in a const jmespath_expression&. This allows a jmespath_expression to be "compiled" once in the code and reused for much better runtime performance. This caches the tokenization.

Person child{};
// A runtime expression can be pre-computed and saved for more efficient lookups
glz::jmespath_expression expression{"family.children[0]"};
expect(not glz::read_jmespath(expression, child, buffer));
expect(child.first_name == "Lilly");

Note that this still works:

expect(not glz::read_jmespath("family.children[0]", child, buffer));

@stephenberry stephenberry changed the title More JMESPath unit tests More JMESPath unit tests and cleanup Dec 17, 2024
@stephenberry stephenberry changed the title More JMESPath unit tests and cleanup JMESPath slices Dec 17, 2024
@stephenberry stephenberry changed the title JMESPath slices JMESPath slices and pre-computed runtime expressions Dec 18, 2024
@stephenberry stephenberry merged commit b05f886 into main Dec 18, 2024
12 checks passed
@stephenberry stephenberry deleted the jmespath branch December 18, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant