Object key with dash symbol
Closed this issue · 2 comments
Hi,
my JSON object contains the dash symbol (-) within the, e.g. { 'seller-sku': 'AB-CDEF-GH' }
and my filter expression var expression = 'seller-sku == "AB-CDEF-GH"';
does not work with that.
So I would need to pre-parse the object and change every object key to camelCase or PascalCase.
Would it be possible to include all possible JSON keys within the expression?
Hey Chris!
Sorry for my late reply. In filtrex, a dash is parsed as a minus sign, the same way it is parsed in JavaScript. You don't have to preprocess anything, instead you can use single-quoted symbols (see filtrex syntax). A trivial example of how to do this would be:
let data = { 'seller-sku': 'AB-CDEF-GH' }
let expr = `'seller-sku' == "AB-CDEF-GH"`
let fn = compileExpression(expr)
fn(data) // 1
Please let me know if this worked for you.
Best regards
Hi Michal!
thank you very much for this answer. It's exactly what I was looking for.
Best regards
Chris