Skip to content

Conversation

prule
Copy link

@prule prule commented Aug 19, 2025

Small change to add a note about how to control how long a jsonata expression can run and control max recursion. It wasn't obvious to me at first and I only found it by browsing the code/tests.

Seems like a pretty important thing any user of the library would want to know to prevent problems.

Feel free to ignore if you don't think its useful.

Thanks for the great library!

@aeberhart
Copy link
Contributor

Thanks for the documentation. @uw4, do we want to keep the depth check? Seems like it only counts up when $eval is called:

  @Test
  public void timeoutTest() {
    var expr = jsonata("[0..9999999].{'x':1}");
    var frame = expr.createFrame();
    frame.setRuntimeBounds(1, 100);
    Assertions.assertThrows(JException.class, () -> expr.evaluate(null, frame));
  }

  @Test
  public void recursionTest() {
    var expr = jsonata("$eval('1' & $eval('1' & $eval('1')))");
    var frame = expr.createFrame();
    frame.setRuntimeBounds(100000, 2);
    Assertions.assertThrows(JException.class, () -> expr.evaluate(null, frame));
  }

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.

2 participants