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

Escaping square brackets #10

Open
fabienblink opened this issue Jun 15, 2022 · 0 comments
Open

Escaping square brackets #10

fabienblink opened this issue Jun 15, 2022 · 0 comments

Comments

@fabienblink
Copy link

fabienblink commented Jun 15, 2022

I am using expression-parser in combination with jsonpath-plus library to parse json paths and read the data out of a json object based on the term returned. Here is what my parser code looks like:

export function initialiseParser(workerObject: WokerObjectType): ExpressionParser {
  return init(formula, (term: string) => {
    if (term === '$NULL') {
      return '$NULL';
    } else if (term.startsWith('$VALUE:')) {
      const [, key] = term.split('$VALUE:');
      return getJsonData({ path: key, json: workerObject }) ?? '$NULL';
    } else {
      return '$NULL';
    }
  });
}

I am trying to parse the below expression:
$VALUE:Worker_Data.Employment_Data.Worker_Job_Data[?(@.attributes['wd:Primary_Job'] === '1')].Position_Data.Business_Site_Summary_Data.Name

When running this through the parser, I can see the term evaluates to .Position_Data.Business_Site_Summary_Data.Name. The result I would like to achieve is to get out the full expression: Worker_Data.Employment_Data.Worker_Job_Data[?(@.attributes['wd:Primary_Job'] === '1')].Position_Data.Business_Site_Summary_Data.Name.

My gut feeling is that the formula language is recognizing the '[]' and parses it at something else but looking through the docs I am unclear as to what.

I wonder is someone could shed some light on this for me? If formula uses [] for something else, how can I escape the character when using it in the expression? Also open to other solutions. Please let me know if more details are required.

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

No branches or pull requests

1 participant