cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
SampleTapir814
Level II

sql JSON_VALUE query and spaces in fields in JSL

I'm trying to query a table in an Oracle table with a field that is JSON. I am using the JSON_VALUE function in the sql. Some of the JSON fields contain spaces so I put double quotes around values and this works when running the query outside of JSL but throws an error running the query as shown below in jsl.  Thanks in advance for any hep you can provide.

 

JSL:

dbc = create database connection("Driver={Oracle in InstantClient11_1};UID=xxxx;DBQ=yyyy;PWD=zzzz;");

 

user_sql ="select json_value(feature, '$."ball dimension"') as ball_dimension from blah";

 

user_dt = execute sql(dbc, user_sql);

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: sql JSON_VALUE query and spaces in fields in JSL

You have to escape those quotes and usually these methods work (I would use option 1)

Names Default To Here(1);

// user_sql ="select json_value(feature, '$."ball dimension"') as ball_dimension from blah";

// Option 1
user_sql1 = "\[select json_value(feature, '$."ball dimension"') as ball_dimension from blah]\";

// Option 2
user_sql2 = "select json_value(feature, '$.\!"ball dimension\!"') as ball_dimension from blah";


// Print demo
Write("\!N" || user_sql1);
Write("\!N" || user_sql2);

 

https://www.jmp.com/support/help/en/18.0/#page/jmp/jsl-syntax-rules.shtml - Look for Double Quotes

jthi_0-1715231918902.png

 

Edit:

Just to add extra some explanation. If you want have double quotes in your string in JMP, you have to escape them (there are also other characters which must be escaped). You can escape single double quote by replacing it with \!" and if you wish to "auto-escape" everything in your string, wrap it with "\[...]\" instead of just "...".

-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: sql JSON_VALUE query and spaces in fields in JSL

You have to escape those quotes and usually these methods work (I would use option 1)

Names Default To Here(1);

// user_sql ="select json_value(feature, '$."ball dimension"') as ball_dimension from blah";

// Option 1
user_sql1 = "\[select json_value(feature, '$."ball dimension"') as ball_dimension from blah]\";

// Option 2
user_sql2 = "select json_value(feature, '$.\!"ball dimension\!"') as ball_dimension from blah";


// Print demo
Write("\!N" || user_sql1);
Write("\!N" || user_sql2);

 

https://www.jmp.com/support/help/en/18.0/#page/jmp/jsl-syntax-rules.shtml - Look for Double Quotes

jthi_0-1715231918902.png

 

Edit:

Just to add extra some explanation. If you want have double quotes in your string in JMP, you have to escape them (there are also other characters which must be escaped). You can escape single double quote by replacing it with \!" and if you wish to "auto-escape" everything in your string, wrap it with "\[...]\" instead of just "...".

-Jarmo
SampleTapir814
Level II

Re: sql JSON_VALUE query and spaces in fields in JSL

Thank you , Jarmo!