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

Reference a key with a dot in it #127

Open
jwhitaker-swiftnav opened this issue Mar 29, 2023 · 1 comment
Open

Reference a key with a dot in it #127

jwhitaker-swiftnav opened this issue Mar 29, 2023 · 1 comment

Comments

@jwhitaker-swiftnav
Copy link

Hey,
Say I have an object

{"my.key":"abc"}

how can I reference this with jsonlogic? if I do

{"var":"my.key"}

it looks for a nested field, but there doesn't seem to be any way to quote the key or avoid this behaviour by other means.

@Emilien-Greenomy
Copy link

In case you're still looking, here's a quick and dirty workaround:

jsonLogic.add_operation('dotvar', function(key){ return this[key] })jsonLogic.apply(
  {
    dotvar: [
      'foo.bar'
    ]
  },
  {'foo.bar': true}
)

You might want to do something more sophisticated, e.g. using lodash get function, which can work with path as arrays of keys and also use bracket notation such as baz["foo.bar"].

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

2 participants