Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError: Maximum call stack size exceeded #21

Closed
yverenoir opened this issue Jul 5, 2017 · 6 comments
Closed

RangeError: Maximum call stack size exceeded #21

yverenoir opened this issue Jul 5, 2017 · 6 comments

Comments

@yverenoir
Copy link

yverenoir commented Jul 5, 2017

Hi,
I am trying to parse json to xml (both in code with json2xml and with cli), but it gives me this error:

/Users/.../node_modules/xml-js/lib/js2xml.js:35
    return (!firstLine && options.spaces ? '\n' : '') + Array(depth + 1).join(options.spaces);
                                                                         ^

RangeError: Maximum call stack size exceeded
    at Array.join (native)
    at writeIndentation (/Users/.../node_modules/xml-js/lib/js2xml.js:35:74)
    at writeElementsCompact (/Users/.../node_modules/xml-js/lib/js2xml.js:225:37)
    at writeElementCompact (/Users/.../node_modules/xml-js/lib/js2xml.js:204:12)
    at writeElementsCompact (/Users/.../node_modules/xml-js/lib/js2xml.js:225:83)
    at writeElementCompact (/Users/.../node_modules/xml-js/lib/js2xml.js:204:12)
    at writeElementsCompact (/Users/.../node_modules/xml-js/lib/js2xml.js:225:83)
    at writeElementCompact (/Users/.../node_modules/xml-js/lib/js2xml.js:204:12)
    at writeElementsCompact (/Users/.../node_modules/xml-js/lib/js2xml.js:225:83)
    at writeElementCompact (/Users/.../node_modules/xml-js/lib/js2xml.js:204:12)
    at writeElementsCompact (/Users/.../node_modules/xml-js/lib/js2xml.js:225:83)
    at writeElementCompact (/Users/.../node_modules/xml-js/lib/js2xml.js:204:12)
    at writeElementsCompact (/Users/.../node_modules/xml-js/lib/js2xml.js:225:83)
    at writeElementCompact (/Users/.../node_modules/xml-js/lib/js2xml.js:204:12)
    at writeElementsCompact (/Users/.../node_modules/xml-js/lib/js2xml.js:225:83)
    at writeElementCompact (/Users/.../node_modules/xml-js/lib/js2xml.js:204:12)

The original json file is:

{
  "vertical": {
    "-display_name": "Exercise",
    "html": { "-url_name": "12345" },
    "lti_consumer": {
      "-url_name": "12345",
      "-xblock-family": "xblock.v1",
      "-accept_grades_past_due": "false",
      "-weight": "14.0",
      "-has_score": "true",
      "-display_name": "Exercise",
      "-ask_to_send_username": "true",
      "-ask_to_send_email": "true",
      "-button_text": "Launch Exercise",
      "-custom_parameters": "none",
      "-lti_id": "id",
      "-launch_target": "new_window",
      "-launch_url": "url"
    }
  }
}

I would be grateful for any insights!

Thanks!
Yve

@yverenoir
Copy link
Author

I tested the original xml file I had and converted it into json, it comes with "_attributes", after adjusting the json file, it solved the problem.

@nashwaan
Copy link
Owner

nashwaan commented Jul 6, 2017

@yverenoir
If this is solved, should this issue be closed?

@bidiu
Copy link

bidiu commented Aug 16, 2017

@yverenoir Can you please explain more about the cause of this issue here? Cause I run into the same issue. Thanks a lot ; )

@nashwaan nashwaan reopened this Aug 16, 2017
@nashwaan
Copy link
Owner

nashwaan commented Aug 16, 2017

@bidiu , 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"}}.

Using, the above json input provided by @yverenoir will not work as it is missing "_text" property. The correct input should be:

{
    "vertical": {
        "-display_name": {
            "_text": "Exercise"
        },
        "html": {
            "-url_name": {
                "_text": "12345"
            }
        },
        "lti_consumer": {
            "-url_name": {
                "_text": "12345"
            },
            "-xblock-family": {
                "_text": "xblock.v1"
            },
            "-accept_grades_past_due": {
                "_text": "false"
            },
            "-weight": {
                "_text": "14.0"
            },
            "-has_score": {
                "_text": "true"
            },
            "-display_name": {
                "_text": "Exercise"
            },
            "-ask_to_send_username": {
                "_text": "true"
            },
            "-ask_to_send_email": {
                "_text": "true"
            },
            "-button_text": {
                "_text": "Launch Exercise"
            },
            "-custom_parameters": {
                "_text": "none"
            },
            "-lti_id": {
                "_text": "id"
            },
            "-launch_target": {
                "_text": "new_window"
            },
            "-launch_url": {
                "_text": "url"
            }
        }
    }
}

Which will produce this result:

<vertical>
    <-display_name>Exercise</-display_name>
    <html>
        <-url_name>12345</-url_name>
    </html>
    <lti_consumer>
        <-url_name>12345</-url_name>
        <-xblock-family>xblock.v1</-xblock-family>
        <-accept_grades_past_due>false</-accept_grades_past_due>
        <-weight>14.0</-weight>
        <-has_score>true</-has_score>
        <-display_name>Exercise</-display_name>
        <-ask_to_send_username>true</-ask_to_send_username>
        <-ask_to_send_email>true</-ask_to_send_email>
        <-button_text>Launch Exercise</-button_text>
        <-custom_parameters>none</-custom_parameters>
        <-lti_id>id</-lti_id>
        <-launch_target>new_window</-launch_target>
        <-launch_url>url</-launch_url>
    </lti_consumer>
</vertical>

For more discussion on why "_text" property is required, see the reasons here and here.

Please let me know if this solves the issue you are facing.

@nashwaan
Copy link
Owner

There is another reason why you might get this error:

If the text value should appear in the attributes of the xml node rather than its body, then "_attributes" is required. For example, {"a": {"b": "hi"}} will not produce <a b="hi">. The correct input is {"a": "_attributes": {"b": "hi"}}}

Thus, @yverenoir has probably used this input to solve his problem:

{
    "vertical": {
        "_attributes": {
            "-display_name": "Exercise"
        },
        "html": {
            "_attributes": {
                "-url_name": "12345"
            }
        },
        "lti_consumer": {
            "_attributes": {
                "-url_name": "12345",
                "-xblock-family": "xblock.v1",
                "-accept_grades_past_due": "false",
                "-weight": "14.0",
                "-has_score": "true",
                "-display_name": "Exercise",
                "-ask_to_send_username": "true",
                "-ask_to_send_email": "true",
                "-button_text": "Launch Exercise",
                "-custom_parameters": "none",
                "-lti_id": "id",
                "-launch_target": "new_window",
                "-launch_url": "url"
            }
        }
    }
}

Which will produce this xml output:

<vertical -display_name="Exercise">
    <html -url_name="12345"/>
    <lti_consumer -url_name="12345" -xblock-family="xblock.v1" -accept_grades_past_due="false" -weight="14.0" -has_score="true" -display_name="Exercise" -ask_to_send_username="true" -ask_to_send_email="true" -button_text="Launch Exercise" -custom_parameters="none" -lti_id="id" -launch_target="new_window" -launch_url="url"/>
</vertical>

@bidiu
Copy link

bidiu commented Aug 16, 2017

@nashwaan Thank you so much for replying and following up. Yes, the cause of my problem is exactly what you said. Right now I solved it.

For the record, what I was trying to do is to convert xml to js (compact version), and then process the js a little, and finally convert it back to xml. The problem is that I set some texts to the js directly. However, I should set the text to "_text" property instead. Thank you once again. The issue could be closed now I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants