Brian Anderson 3 Posted October 11, 2016 Posted October 11, 2016 If someone has a good tutorial link, link or has answer that would be excellent. I need JSON output similar to this: { "sample_json_output": { "status" : 1, "status_message" : "NULL", "result" : { "details": { "id" : 1234, "title" : "A Title", "description": "Descriptive text here" } }, "empty_array": [] } } I don't know xsd formatting at all, and xml only a little more. The CIS documentation is too simplified to describe this, and I'm unable to find a solution on the web.
Christopher Ballenger Posted October 11, 2016 Posted October 11, 2016 Try this ins a stored procedure. OUT status INT,OUT status_message VARCHAR(255),OUT result CURSOR ( id INT, title VARCHAR(255), description TEXT),OUT empty_array CURSOR() In the Web Service you can update the name insread of the output saying StoreProcesureStatus. If the array is empty it will show empty_array = NULL in the json output. I hope this helps!
Brian Anderson 3 Posted October 11, 2016 Author Posted October 11, 2016 Close, but not the result I'm looking for. Here's what I got when I published the procedure: { "p_test_empty_array": { "status": 1, "status_message": "", "result": { "data_set_details": [ { "id": 1234, "name": "blarg", "description": "nonsense junk here", "class_name": "low" } ] }, "empty_array": "" }} The empty_array isn't an array, it's an empty string. The developers who consume this REST service expect to see: "empty_array": [] -- open/close brackets. Or, they would also accept no "empty_array" attribute at all if no data is returned for that part. A Cisco consultant here said it wasn't possible to get the former without and XSD (definition set), thus the reason for my post.
Brian Anderson 3 Posted January 20, 2017 Author Posted January 20, 2017 I figured out how to remove the empty array element by editing the XQuery for the transformation. It looks for an empty string in one of the array's elements - if null it ends there, otherwise it prints out all of the elements. { let $nodes := ( let $inputs := (if (empty($in_name)) then "NULL" else concat(concat("'",$in_name), "'") cast as xs:string) let $query := concat( "select status,status_message,id,title,description,characterization,first_name,last_name,nickname,occupation,user_id from /shared/snipped_to_protect_the innocent(", concat( string-join($inputs,","), ")")) let $data_set_details1 := composite:executeQuery($query)//result for $data_set_details in $data_set_details1 return element ns1:data_set_details { element ns1:status {$data_set_details/status/text()}, element ns1:status_message {$data_set_details/status_message/text()}, let $nodes := ( element ns1:result { let $nodes := ( element ns1:data_set_detail { element ns1:id {$data_set_details/id/text()}, element ns1:title {$data_set_details/title/text()}, element ns1:description {$data_set_details/description/text()}, element ns1:characterization {$data_set_details/characterization/text()}, for $data_set_details in $data_set_details1 return ----> if (empty($data_set_details/user_id/text())) then
Christopher Ballenger Posted January 22, 2017 Posted January 22, 2017 Very nice. Does this work for JSON response
Brian Anderson 3 Posted February 7, 2017 Author Posted February 7, 2017 The web service I'm working to fix is a JSON REST service, so yes, the array is not included in the JSON response if the element I examine is null, otherwise the array is shown when there is data.
James Gilmour Posted March 13, 2017 Posted March 13, 2017 A little late, you should be able to manually create an XSD or use something like xmlspy to define an XSD for you if you have an example XML output. We've had to manually configure and XSD to ensure a consistent format. Looks like you may already have an answer but hope it helps for future reference.
Christopher Ballenger Posted March 17, 2017 Posted March 17, 2017 What version of CIS are you running I tried this in the past and couldn't get it to work.
Brian Anderson 3 Posted March 23, 2017 Author Posted March 23, 2017 Hi Chris, I don't think version's matter since I modified the XQuery generated by the transformation. Is that what you're talking about when you say it didn't work
Akshatha Shete Posted January 31, 2020 Posted January 31, 2020 Any solution on this I am facing same issue.
Dave Richardson Posted February 28, 2020 Posted February 28, 2020 I'm also looking for a similar solution for an XML web service published in DV. The response does not include an empty array object when there is no data, but it really should. It looks like "array_object": [] when it should look like "array_object": [{}]
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now