Skip to content

Commit 42f657a

Browse files
committed
fix: parse yaml to json on client always
1 parent 3bebfe3 commit 42f657a

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

cmd/wasm/functions.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,7 @@ type IncompleteOverlayErrorMessage struct {
181181
}
182182

183183
func applyOverlayJSONPathIncomplete(result []*yaml.Node, node *yaml.Node) (string, error) {
184-
var data interface{}
185-
if len(result) == 1 {
186-
data = result[0]
187-
} else {
188-
data = result
189-
}
190-
191-
yamlResult, err := yaml.Marshal(data)
184+
yamlResult, err := yaml.Marshal(&result)
192185
if err != nil {
193186
return "", err
194187
}

web/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"react-resizable-panels": "^2.1.7",
3030
"tailwind-merge": "^2.6.0",
3131
"tailwindcss-animate": "^1.0.7",
32-
"usehooks-ts": "^3.1.0"
32+
"usehooks-ts": "^3.1.0",
33+
"yaml": "^2.7.0"
3334
},
3435
"devDependencies": {
3536
"@types/node": "^22.10.5",

web/pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/src/Playground.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
} from "./lib/utils";
3232
import ShareDialog, { ShareDialogHandle } from "./components/ShareDialog";
3333
import { Loader2Icon, ShareIcon } from "lucide-react";
34+
import { parse as yamlParse } from "yaml";
3435

3536
const Link = ({ children, href }: { children: ReactNode; href: string }) => (
3637
<a
@@ -110,7 +111,16 @@ function Playground() {
110111
tryHandlePageTitle(JSON.parse(info));
111112
} else if (response.type == "incomplete") {
112113
setApplyOverlayMode("jsonpathexplorer");
113-
changed.current = formatDocument(response.result);
114+
115+
if (originalLang.current == "json") {
116+
// !TODO: this is a hack to get around the fact
117+
// that the json parser only returns yaml.
118+
const obj = yamlParse(response.result);
119+
changed.current = JSON.stringify(obj, null, 2);
120+
} else {
121+
changed.current = response.result;
122+
}
123+
114124
setError("");
115125
setOverlayMarkers([]);
116126
} else if (response.type == "error") {

web/src/assets/wasm/lib.wasm

-706 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)