1

The document has below structure

 {
    "sNo": 0,
    "id": 31575378,
    "title": "Sustained preventive chemotherapy",
    "journal": "Infectious diseases of poverty",
    "publ_date": "2019-10-03",
    "species": "Human",
    "drug": ["Allegra", "Citrizin"],
    "symptom": ["Cold", "Cough", "Fatigue"]
 }

When I try to extract drug json property from the document

<extract-document-data>
                            <extract-path>/drug</extract-path>                                                                                  
                     </extract-document-data>

I get a response like

<search:extracted kind="array">{"drug":"Dolo"}, {"drug":"Crocin"}, {"drug":"Combiflame",{"symptom":"Fever"} {"symptom":"Body Pain"}{"symptom":"Fatiguue"}]</search:extracted>

whereas I am looking for output where drug would be an json array as:

<search:extracted kind="array">[{"drug":["Dolo","Crocin","Combiflame"]}]</search:extracted>

1 Answers1

0

Does it work to specify the extract path as:

/array-node("drug")

When applying named XPath steps to JSON, MarkLogic skips over array containers to match array value items. (Similarly, MarkLogic skips over object containers to match object properties.)

To match the container, the XPath should provide an explicit node test such as array-node() or object-node()

For more detail, see:

https://docs.marklogic.com/guide/app-dev/json#id_15818

Hoping that helps,

ehennum
  • 7,295
  • 13
  • 9