-
Notifications
You must be signed in to change notification settings - Fork 181
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
Is there an option to parent the fields of an _attributes object
on the parent object.
#56
Comments
I'm going to close this. I just realized I can easily use |
@michaelgwelch , Can you share an example of how you used |
@nashwaan Sure I can post the code I used. But others trying to follow my advice, my example is relatively simple. The first thing I did was manually edit my JSON file so that instead of having something like {
"a": [
{
"_attributes": {
"val": "5"
}
},
{
"_attributes": {
"val": "6"
}
}
]
} I had [
{
"_attributes": {
"val": "5"
}
},
{
"_attributes": {
"val": "6"
}
}
] In other words, I removed the top level parent object, leaving me with just a JSON array. So applying map was quite simple. Assuming a file named #!/usr/bin/evn node
const origEvents = require('./events.json');
const newEvents = origEvents.map( (val) => { return val["_attributes"] });
console.log(JSON.stringify(newEvents, null, 2)) Then from bash $ chmod +x convert.js
$ ./convert.js > output.json Note: my objects actually had dozens of fields, but for the sake of this example that isn't relevant. Just the shape of the JSON is what is relevant. To recap: I started with XML that had this shape: <a val="5" />
<a val="6" /> Then I used |
Although mapping works, it's annoying if your documents follow the element-attribute format, where it really makes way more sense to have the attribute kvs be added directly to the element object. Here's a quick working pr that makes this work #195 |
Pardon me if that question is very poorly worded.
Basically I have an XML document where each XML element has attributes, but no child elements. So it's safe to skip the creation of an
_attributes
object. The attributes themselves can go right on the generated JSON object.Example: Given
I'd like the output to be (Note, I can make
a
plural myself as in this example)rather than
The text was updated successfully, but these errors were encountered: