JavaScript filter in Druid

Hi team,

I enabled JAVA SCRIPT Filter in druid 0.10.0. I Would like to filter one of my Dimension which is holding JSON values in string Format

example: dime1={“name”:“sai”, “age”: 23, “height”: 5.6}

dime1={“name”:“chandu”, “age”: 23, “height”: 4.6}

—Now i would like to filter all my dime1 fields where age is equal to 23

i tried using JAVA-SCRIPT Filter in this docs

{ “type”: “javascript”, “dimension”: “some_details”, “function”: "function(x) { var obj = JSON.parse(x); if(obj.age==23){return(JSON.stringify(obj))} }

but its giving this error…

Error: - {

“error”: “Unknown exception”,

“errorMessage”: “SyntaxError: Unexpected token in object literal (script#1)”,

“errorClass”: “org.mozilla.javascript.EcmaError”,

“host”: “


what is the proper syntax for JAVASCRIPT filter to search JSON string values in dimensions,?

Thanks in advance,



Hi Sai,

I’m not sure what is causing this, but maybe you could try using a JS try/catch to suppress parsing errors. It’s possible some of your values aren’t valid JSON.

It’s also possible I don’t understand the JS you wrote and there is something wrong with it that I can’t see :slight_smile: