How to feed a dynamic dropdown with a rest service which send application/json

20 views
Skip to first unread message

vicaed

unread,
Feb 9, 2018, 3:02:44 PM2/9/18
to orb...@googlegroups.com
Hi everyone, I don´t get feed the dynamic dropdown when I receive data from a
web service in JSON format. I can use the same service if i get xml setting
the dropdown as follow:

resource url: http://opendata.gijon.es/descargar.php?id=113&tipo=XML
xpath expression for the node:
/empresa_grupo_niveles/empresa_grupo_nivel/num_empleados
xpath expression for label and value: .

and to consum JSON I tried:

resource url: http://opendata.gijon.es/descargar.php?id=113&tipo=JSON
xpath expression for the node: /empresa_grupo_niveles or
instance()/empresa_grupo_niveles neither works
xpath expression for label and value: instance()/empresa_grupo_nivel/_[2]

Please notice that I test with the http service that web service is working
with both xml and JSON format, I think the problem is that I don't write the
right xpath expression for JSON.


--
Sent from: http://discuss.orbeon.com/

vicaed

unread,
Feb 12, 2018, 5:57:51 AM2/12/18
to orb...@googlegroups.com
Ok, I got it so I will respond to myself just in case someone could have the
same doubte. The json structure is as I show below:
<http://discuss.orbeon.com/file/t375607/json_structure.png>

So the right Xpath expresion is:

- For the node:
/instance()/empresa_grupo_niveles/empresa_grupo_nivel/_[.]/num_empleados . I
think one of my previous mistakes was ommit the initial '/' . And apparently
if you put '.' in the array element, you get all elements of the array, then
if every element is a group of elements you have to specify what of them you
want to show, in my case '/num_empleados

- For the value: I just wrote '.'

Alessandro Vernet

unread,
Feb 13, 2018, 12:44:28 AM2/13/18
to orb...@googlegroups.com
Hi Vicente,

Sorry for the late response. I'm glad your persistence paid off, and you
should also be able to use the following, which is a but a simpler than what
you had:

Choices XPath: /json/empresa_grupo_niveles/empresa_grupo_nivel/_
Label XPath: num_empleados
Value XPath: num_empleados

Orbeon Forms follows the rules defined in the XForms 2.0 spec to convert
JSON to XML (see link below), but granted, we can't expect everyone to be
familiar with those rules ;), so I think it might be useful to offer a
preview that XML somewhere. We could maybe do this in the HTTP Service
Editor, since we already have a Test Results tabs there. We'll need to think
a little bit more about this one.

https://www.w3.org/community/xformsusers/wiki/XForms_2.0#External_JSON_values

Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet

Alessandro Vernet

unread,
Feb 13, 2018, 7:20:29 PM2/13/18
to orb...@googlegroups.com
Hi Vicente,

And for reference, we've added this RFE:
https://github.com/orbeon/orbeon-forms/issues/3474

vicaed

unread,
Feb 15, 2018, 3:29:58 AM2/15/18
to orb...@googlegroups.com
Hi Alex, thanks you for the additional information.

EsamNaas

unread,
Sep 26, 2019, 3:03:10 PM9/26/19
to orb...@googlegroups.com
Hi Alessandro,

Thanks for you help, could you please let us know how to apply filter
expression to XPATH please for example this should give me a list of all
countries in Europe
continent[@name='Europe']/_

many thanks

Esam

Alessandro Vernet

unread,
Sep 26, 2019, 3:24:49 PM9/26/19
to orb...@googlegroups.com
Hi Esam,

It depends what the service returns. Would you be able to attach the XML or
JSON your service returns?

‑Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet

Esam Naas

unread,
Sep 27, 2019, 3:54:33 AM9/27/19
to orb...@googlegroups.com
I'm using http service with GraphQL to feed Orbeon form with reference data
from mongoDB
the JSON:
{
"data": {
"getrefdatavalues": [
{
"RefDataSet": "DSNReferralReason_Amber",
"Value": "iv-insulin-with-good-glucose-control",
"Label": "IV insulin with good glucose control"
},
{
"RefDataSet": "DSNReferralReason_Amber",
"Value": "nil-by-mouth-for-more-than-24-hours",
"Label": "Nil by mouth for more than 24 hours"
},
{
"RefDataSet": "DSNReferralReason_Amber",
"Value": "preoperative-optimisation-for-elective-surgery",
"Label": "Preoperative optimisation for elective surgery"
},
{
"RefDataSet": "DSNReferralReason_Amber",
"Value": "significant-educational-need",
"Label": "Significant educational need"
},
{
"RefDataSet": "DSNReferralReason_Amber",
"Value": "persistent-hyperglycaemia",
"Label": "Persistent hyperglycaemia"
},
{
"RefDataSet": "DSNReferralReason_Amber",
"Value": "mental-health-issues",
"Label": "Mental health issues"
},
{
"RefDataSet": "DSNReferralReason_Amber",
"Value": "stress-hyperglycaemia",
"Label": "Stress hyperglycaemia"
},
{
"RefDataSet": "DSNReferralReason_Amber",
"Value": "poor-wound-healing",
"Label": "Poor wound healing"
},
{
"RefDataSet": "DSNReferralReason_Amber",
"Value": "steroid-therapy",
"Label": "Steroid therapy"
},
{
"RefDataSet": "DSNReferralReason_Amber",
"Value": "hyperglycaemia-following-pancreatic-surgery",
"Label": "Hyperglycaemia following pancreatic surgery"
},
{
"RefDataSet": "DSNReferralReason_Amber",
"Value": "unstable-blood-glucose-levels-after-24-48hr-monitoring",
"Label": "Unstable blood glucose levels after 24-48hr monitoring"
},
{
"RefDataSet": "DSNReferralReason_Amber",
"Value": "patient-request",
"Label": "Patient request"
},
{
"RefDataSet": "DSNReferralReason_Green",
"Value": "minor-self-treated-hyperglycaemia",
"Label": "Minor, self-treated hyperglycaemia"
},
{
"RefDataSet": "DSNReferralReason_Green",
"Value": "transient-hyperglycaemia",
"Label": "Transient hyperglycaemia"
},
{
"RefDataSet": "DSNReferralReason_Green",
"Value": "simple-educational-needs",
"Label": "Simple educational needs"
},
{
"RefDataSet": "DSNReferralReason_Green",
"Value": "routine-dietetic-advice",
"Label": "Routine dietetic advice"
},
{
"RefDataSet": "DSNReferralReason_Green",
"Value": "routine-diabetic-advice",
"Label": "Routine diabetic advice"
},
{
"RefDataSet": "DSNReferralReason_Green",
"Value": "well-controlled-diabetes",
"Label": "Well controlled diabetes"
},
{
"RefDataSet": "DSNReferralReason_Green",
"Value": "good-self-management-skills",
"Label": "Good self-management skills"
},
{
"RefDataSet": "DSNReferralReason_Green",
"Value": "routine-diabetes-care",
"Label": "Routine diabetes care"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "stroke-tia",
"Label": "Stroke / TIA"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "admission-for-emergency-surgery",
"Label": "Admission for emergency surgery"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "admission-for-urgent-major-surgery",
"Label": "Admission for urgent major surgery"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "urgent-review-for-elective-surgical-procedure",
"Label": "Urgent review for elective surgical procedure"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "acute-coronary-syndrome",
"Label": "Acute coronary syndrome"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "diabetic-ketoacidosis-dka",
"Label": "Diabetic ketoacidosis (DKA)"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "impending-dka",
"Label": "Impending DKA"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "hyperosmolar-hyperglycaemic-state-(hhs)",
"Label": "Hyperosmolar hyperglycaemic state (HHS)"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "hypoglycaemia",
"Label": "Hypoglycaemia"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "hypoglycaemia-unawareness",
"Label": "Hypoglycaemia unawareness"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "eating-disorders",
"Label": "Eating disorders"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "sepsis",
"Label": "Sepsis"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "vomiting",
"Label": "Vomiting"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "impaired-consciousness",
"Label": "Impaired consciousness (risk of discharge delay or
admission)"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "unable-to-self-manage",
"Label": "Unable to self-manage"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "parenteral-or-enteral-nutrition",
"Label": "Parenteral or enteral nutrition"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "high-risk-foot-problem",
"Label": "High risk foot problem"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "newly-diagnosed-or-suspected-type-1-diabetes",
"Label": "Newly diagnosed or suspected Type 1 diabetes"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "newly-diagnosed-or-suspected-type-2-diabetes",
"Label": "Newly diagnosed or suspected Type 2 diabetes"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "iv-insulin-infusion-for-over-24-hours",
"Label": "IV insulin infusion for over 24 hours"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "iv-insulin-with-glucose-outside-limits",
"Label": "IV insulin with glucose outside limits"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "recurring-diabetes-related-admission",
"Label": "Recurring diabetes-related admission"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "ketoacidosis-post-pancreatectomy",
"Label": "Ketoacidosis post pancreatectomy"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "declining-renal-function",
"Label": "Declining renal function"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "high-dose-steroid-therapy",
"Label": "High dose steroid therapy"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "insulin-pump-patient",
"Label": "Insulin pump patient"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "pre-conception-planning",
"Label": "Pre-conception planning"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "pregnant-woman-with-diabetes",
"Label": "Pregnant woman with diabetes"
},
{
"RefDataSet": "DSNReferralReason_Red",
"Value": "end-of-life-advanced-care-planning",
"Label": "End-of-life advanced care planning"
}
]
}
}

I have action to select which referral category (Red,Amber,Green)
I'm trying to filter for "DSNReferralReason_Red"
XPATH: /json/data/getrefdatavalues[@RefDataSet = 'DSNReferralReason_Red']/_

<http://discuss.orbeon.com/file/t375773/orbeon-jsonpath.png>

Esam Naas

unread,
Oct 1, 2019, 12:50:46 PM10/1/19
to orb...@googlegroups.com
Thanks Alessandro, after you answered my other post I figured out what path i
should write
XPATH: /json/data/getrefdatavalues/_[RefDataSet = 'DSNReferralReason_Red'].

Regards,

Esam

Alessandro Vernet

unread,
Oct 1, 2019, 6:49:45 PM10/1/19
to orb...@googlegroups.com
Perfect, and for anyone who happens find this through a search, here is the
other thread Esam referenced:

http://discuss.orbeon.com/JSONPATH-td4664735.html

‑Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply all
Reply to author
Forward
0 new messages