throwing an error 'Maximum call stack Size exceeded' when trying to convert from json to xml

506 Views Asked by At

I have below xml

<measureDef><formula><aggFunction type="sum"><expression><field>ADMIT</field><factTable>ADMIT</factTable><aggregation>SUM</aggregation></expression></aggFunction></formula></measureDef>

and I have converted into json as

let dimensionJson = { "measureDef":{                
                        "formula": {
                           "aggFunction": {
                            "_attributes": {
                                "type": "sum"
                            },
                              "expression": {
                                 "field": "ADMIT",
                                 "factTable": "ADMIT",
                                 "aggregation": "SUM"
                              }
                           }
                        }            
                }
}

Now,in some case I want to convert this Json to xml.So,I'm trying to convert

const xml2JsonOptionsDefault = { compact: true, spaces: 0 };
    console.log('FORMULA ARRAY', convert.js2xml(dimensionJson, xml2JsonOptionsDefault));

It is throwing 'maximum call stack size exceeded'.Could someone tell me why it is happening?

1

There are 1 best solutions below

0
On

From a similar issue in the repo:

... you probably missing "_text" property in your json input. For example, {"a": "hi"} will not produce <a>hi</a>. The correct input is {"a":{"_text":"hi"}}.

This is untested, but you might need to include a "_text" property for any properies in your JSON that are going to have values in the XML.

Example:

let dimensionJson = {
    "measureDef": {
        "formula": {
            "aggFunction": {
                "_attributes": {
                    "type": "sum"
                },
                "expression": {
                    "aggregation": {
                        "_text": "SUM"
                    },
                    "factTable": {
                        "_text": "ADMIT"
                    },
                    "field": {
                        "_text": "ADMIT"
                    }
                }
            }
        }
    }
}