When using the json{} displayer, if an attribute name is tag, text, you get misleading results:
# echo '<div tag="hello">world</div>' |./pup 'div json{}'
[
{
"tag": "div",
"text": "world"
}
]
tag=hello attribute has disappeared
# echo '<div text="hello">world</div>' |./pup 'div json{}'
[
{
"tag": "div",
"text": "hello world"
}
]
text=hello attribute has been appended to text
Both these issues can be solved by giving attributes their own object underneath the node object
# echo '<div tag="hello">world</div>' |./pup 'div json{}'
[
{
"attrs": {
"tag": "hello"
},
"tag": "div",
"text": "world"
}
]
# echo '<div text="hello">world</div>' |./pup 'div json{}'
[
{
"attrs": {
"text": "hello"
},
"tag": "div",
"text": "world"
}
]
When using the
json{}displayer, if an attribute name istag,text, you get misleading results:tag=helloattribute has disappearedtext=helloattribute has been appended to textBoth these issues can be solved by giving attributes their own object underneath the node object