### Bug description

Commit c5b6176 seems to have broken our Panflute filters.

As of that commit, when we do `quarto render`, we get the following traceback:

```
Traceback (most recent call last):
  File "/Users/mb312/dev_trees/test-quarto/a_filter", line 19, in <module>
    main()
  File "/Users/mb312/dev_trees/test-quarto/a_filter", line 13, in main
    return run_filter(action,
  File "/Users/mb312/dev_trees/panflute/panflute/io.py", line 230, in run_filter
    return run_filters([action], *args, **kwargs)
  File "/Users/mb312/dev_trees/panflute/panflute/io.py", line 203, in run_filters
    doc = load(input_stream=input_stream)
  File "/Users/mb312/dev_trees/panflute/panflute/io.py", line 61, in load
    doc = json.loads(in_text, object_hook=from_json)
  File "/opt/homebrew/Cellar/python@3.10/3.10.11/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
  File "/opt/homebrew/Cellar/python@3.10/3.10.11/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/homebrew/Cellar/python@3.10/3.10.11/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
  File "/Users/mb312/dev_trees/panflute/panflute/elements.py", line 1424, in from_json
    assert (len(data) == 1) or (len(data) == 2 and 'c' in data)
AssertionError
Error running filter /Users/mb312/dev_trees/quarto-cli/src/resources/filters/main.lua:
Error running filter /Users/mb312/dev_trees/test-quarto/a_filter:
Filter returned error status 1
```

The reproducer below shows that this is - at least - when there is markup of form `{{< var a_var >}}` or `{{< meta title >}}`.

This turns out to be because the JSON passed down into Panflute breaks on a Panflute assumption.

Reproducer : clone <https://github.com/matthew-brett/test-quarto> and `quarto render`.

Investigation of JSON - to get JSON passed to filter, use development version of `panflute`.  Patch `panflute` with:

```diff
diff --git a/panflute/io.py b/panflute/io.py
index d95d81e..5160767 100644
--- a/panflute/io.py
+++ b/panflute/io.py
@@ -55,7 +55,10 @@ def load(input_stream=None):
         input_stream = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
 
     # Load JSON and validate it
-    doc = json.load(input_stream, object_hook=from_json)
+    in_text = input_stream.read()
+    with open('here.json', 'wt') as fobj:
+        fobj.write(in_text)
+    doc = json.loads(in_text, object_hook=from_json)
 
     # Notes:
     # - The hook gets called for dicts (not lists), and the deepest dicts
```

Add any Panflute filter to list of filters in `_quarto.yml`.  The `test-quarto` project above has one such, called `a_filter`.

Run `quarto render` to get error (and write `here.json`, the input JSON to the filter).   Now run:

```python
import json

from panflute import elements

contents = open('source/here.json', 'rt').read()
json.loads(contents, elements.from_json)
```

reproduces the error.

Running on macOS 13.3.1.

```
$ quarto check
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.2: OK
      Dart Sass version 1.55.0: OK
      Deno version 1.33.1: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 99.9.9
      Path: /Users/mb312/dev_trees/quarto-cli/package/dist/bin

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.10.11
      Path: /Users/mb312/.virtualenvs/resampling-with/bin/python3
      Jupyter: 5.3.0
      Kernels: ir

      NOTE: No Jupyter kernel for Python found

[✓] Checking R installation...........OK
      Version: 4.3.0
      Path: /opt/homebrew/Cellar/r/4.3.0_1/lib/R
      LibPaths:
        - /Users/mb312/Library/R/arm64/4.3/library
        - /opt/homebrew/lib/R/4.3/site-library
        - /opt/homebrew/Cellar/r/4.3.0_1/lib/R/library
      knitr: 1.42
      rmarkdown: 2.21

[✓] Checking Knitr engine render......OK
```



### Checklist

- [X] Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
- [X] Please [format your issue](https://quarto.org/bug-reports.html#formatting-make-githubs-markdown-work-for-us) so it is easier for us to read the bug report.
- [x] Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- [X] Please document the operating system you're running. If on Linux, please provide the specific distribution.
- [X] Please provide the output of `quarto check` so we know which version of quarto and its dependencies you're running.
cscheid
2023-05-06T18:01:06Z
matthew-brett
bug enhancement upstream
v1.4
closed
JSON input with var markup breaks Panflute filters
https://github.com/quarto-dev/quarto-cli/issues/5443