Skip to content

Commit

Permalink
fix: parse yaml to json on client always
Browse files Browse the repository at this point in the history
  • Loading branch information
walker-tx committed Feb 23, 2025
1 parent 3bebfe3 commit 42f657a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
9 changes: 1 addition & 8 deletions cmd/wasm/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,7 @@ type IncompleteOverlayErrorMessage struct {
}

func applyOverlayJSONPathIncomplete(result []*yaml.Node, node *yaml.Node) (string, error) {
var data interface{}
if len(result) == 1 {
data = result[0]
} else {
data = result
}

yamlResult, err := yaml.Marshal(data)
yamlResult, err := yaml.Marshal(&result)
if err != nil {
return "", err
}
Expand Down
3 changes: 2 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"react-resizable-panels": "^2.1.7",
"tailwind-merge": "^2.6.0",
"tailwindcss-animate": "^1.0.7",
"usehooks-ts": "^3.1.0"
"usehooks-ts": "^3.1.0",
"yaml": "^2.7.0"
},
"devDependencies": {
"@types/node": "^22.10.5",
Expand Down
3 changes: 3 additions & 0 deletions web/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion web/src/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
} from "./lib/utils";
import ShareDialog, { ShareDialogHandle } from "./components/ShareDialog";
import { Loader2Icon, ShareIcon } from "lucide-react";
import { parse as yamlParse } from "yaml";

const Link = ({ children, href }: { children: ReactNode; href: string }) => (
<a
Expand Down Expand Up @@ -110,7 +111,16 @@ function Playground() {
tryHandlePageTitle(JSON.parse(info));
} else if (response.type == "incomplete") {
setApplyOverlayMode("jsonpathexplorer");
changed.current = formatDocument(response.result);

if (originalLang.current == "json") {
// !TODO: this is a hack to get around the fact
// that the json parser only returns yaml.
const obj = yamlParse(response.result);
changed.current = JSON.stringify(obj, null, 2);
} else {
changed.current = response.result;
}

setError("");
setOverlayMarkers([]);
} else if (response.type == "error") {
Expand Down
Binary file modified web/src/assets/wasm/lib.wasm
Binary file not shown.

0 comments on commit 42f657a

Please sign in to comment.