-
Notifications
You must be signed in to change notification settings - Fork 110
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
Response object switching from array to object value based on number of results #91
Comments
That sounds very logical. I'm curious to check if the response from Amazon
is causing this or if it is the XML to JSON that is causing this issue. It
sounds like you are saying XML to JSON is the culprit. In any case,
normalizing it sounds like a great idea. I probably won't get around to
this soon. Feel free to submit a PR if you want it done soon.
…On Thu, Nov 30, 2017 at 9:57 PM rmzg ***@***.***> wrote:
A problem I frequently run into is when the value of a given key somewhat
randomly switches between an array value and an object value. In my most
recent they key is the ItemLookupResponse.Items.Item which sometimes
contains an array and sometimes contains a single object which tends to
cause errors like TypeError: Cannot read property 'length' of undefined.
Obviously the reason why it switches is because sometimes there's multiple
values and sometimes there's a single value, which is why you can't use a
generic function to translate XML in to JSON since they're not the same
type of structure.
This can be worked around in the requiring code with some annoyance but
would make for much simpler code if it was fixed in the library code, which
in this case means that Items.Item should always be an array.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#91>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAHIcS34oTn-SJAHji40e-R_V22Dx44Tks5s74c3gaJpZM4Qx3lM>
.
|
Obviously it's the |
It's not due to this option? const defaultXml2JsOptions = { |
How can I change this just for test ? |
Change what? |
explicitArray: false to true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A problem I frequently run into is when the value of a given key somewhat randomly switches between an array value and an object value. In my most recent they key is the
ItemLookupResponse.Items.Item
which sometimes contains an array and sometimes contains a single object which tends to cause errors likeTypeError: Cannot read property 'length' of undefined
.Obviously the reason why it switches is because sometimes there's multiple values and sometimes there's a single value, which is why you can't use a generic function to translate XML in to JSON since they're not the same type of structure.
This can be worked around in the requiring code with some annoyance but would make for much simpler code if it was fixed in the library code, which in this case means that
Items.Item
should always be an array.The text was updated successfully, but these errors were encountered: