candle icon indicating copy to clipboard operation
candle copied to clipboard

Support printing out JSON

Open gabebw opened this issue 4 years ago • 0 comments

Like pup: https://github.com/EricChiang/pup#json

Candle supports printing out information for multiple selectors (a {text}, link {text}, while Pup only prints information for one final selector. That makes printing out the JSON a bit weird, because then candle might print JSON mixed with text (e.g. a {json}, link {text}). Candle could let people do that, but it's very unlikely to be what people want. Let's enforce that {json} must be the final and only operator.

I think the JSON format should differ slightly from pup's in that it should always print out an array of objects, even if there's only one object.

Also maybe nice to have would be allowing it to filter to specific attributes, like div json{class}, which would print only the class for divs, and would not print the children at all. So given `

:
{
  "tag": "div",
  "attributes": [{ "class": "whatever" }],
  "children": []
}

To support that, the selector should be json{OPTIONAL_ATTRS}, not {json}, and thus {html} should probably be html{} too, for consistency.

gabebw avatar Sep 03 '19 15:09 gabebw