-
Notifications
You must be signed in to change notification settings - Fork 94
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
Possible to force array? #23
Comments
Hi Gary, I am really sorry for the delay. I haven't had much time to dedicate to this project lately. Yes someone implemented this functionality on PR #16. I think you can do something like that: xml := strings.NewReader(`...`)
json, err := xj.Convert(
xml,
xj.WithNodes(
xj.NodePlugin("rss.channel.item.apps.app", xj.ToArray()),
),
) Let me know if it works. |
By trying, it looks to me that the way it works is by addressing the parent object holding the array, that is
The problem with this is when the parent object also has attributes.. this is not rendered correctly; you can check by this test case:
In this test, The expected result I would like is the following:
whereas I currently get this:
As you see, although zoo becomes an array, where the transformation is applied, also the attributes of bar are translated hence screwing things up |
I think I'm figuring it out, the I also think that a better approach would be to not indicate the parent whose children must be arrays, but instead the children that are array objects. This way you could selectively discriminate between properties and items (and items of different types) |
Considers arrays see issue basgys#23 basgys#23 (comment)
Considers arrays see issue basgys#23 basgys#23 (comment)
Considers arrays see issue basgys#23 basgys#23 (comment)
It may be an attribute <?xml version="1.0" encoding="UTF-8"?>
<rss>
<channel>
<item>
<apps>
<app array="true">App One</app>
</apps>
</item>
<item>
<apps>
<app>App Two</app>
<app>App Three</app>
</apps>
</item>
</channel>
</rss> {
"rss": {
"channel": {
"item": [
{
"apps": {
"app": [
"App One"
]
}
},
{
"apps": {
"app": [
"App Two",
"App Three"
]
}
}
]
}
}
} |
Hi, is it possible for force an array? For example i have the following xml:
which converts to
The problem is that the Apps/app node is an object but the second & third Apps/app node is an array. I understand why given the structure, but is it possible to force the first node to also be an array?
Tks,
Gary
The text was updated successfully, but these errors were encountered: