Skip to content

Commit

Permalink
Remove optIndent
Browse files Browse the repository at this point in the history
Always format the JSON output. Add scaffolding for the anticipated
normalized path location option.
  • Loading branch information
theory committed Dec 22, 2024
1 parent 714e143 commit 49f294c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $(DST_DIR)/play.css: $(SRC_DIR)/play.css

$(DST_DIR)/index.html: $(SRC_DIR)/index.html
mkdir -p $(@D)
version=$$(grep jsonpath go.mod | awk '{print $$3}'); cat $< | sed -e "s!{{version}}!$${version}!g" > $@
version=$$(grep jsonpath go.mod | awk '{print $$3}'); cat $< | sed -e "s!{{version}}!$${version}!g" > $@

$(DST_DIR)/wasm_exec.js: $(WASM_EXEC)
mkdir -p $(@D)
Expand Down
14 changes: 8 additions & 6 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<meta charset="utf-8">
<title>Go JSONPath Playground</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="play.css">
Expand All @@ -11,7 +11,7 @@
const $$ = (q) => document.querySelector(q);

const optionNames = [
"optIndent",
//"optLocated",
];

const EXAMPLE_JSON = {
Expand Down Expand Up @@ -264,7 +264,7 @@ <h2>
</div>
</noscript>
<div id="fluid">
<input id="path" placeholder="Enter a JSONPath query…" />
<input id="path" placeholder="Enter a JSONPath query…">
<div id="go">
<button id="exec-btn">Run Query</button>
<button id="permalink"
Expand All @@ -278,10 +278,12 @@ <h2>
</label>
</div>
<div id="output">
<label for="optIndent" class="opt" title ="Pretty print the JSON value">
<input id="optIndent" type="checkbox" checked />
Pretty
<!--
<label for="optLocated" class="opt" title ="Show the normalized path location of each value">
<input id="optLocated" type="checkbox">
Located
</label>
-->
<label for="values" title="The values selected from the JSON Input">Query Output
<textarea id="values" readonly>[]</textarea>
</label>
Expand Down
9 changes: 5 additions & 4 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
)

const (
optIndent int = 1 << iota
optLocated int = 1 << iota
)

func main() {
stream := make(chan struct{})

js.Global().Set("query", js.FuncOf(query))
js.Global().Set("optIndent", js.ValueOf(optIndent))
// js.Global().Set("optLocated", js.ValueOf(optLocated))

<-stream
}
Expand Down Expand Up @@ -51,8 +51,9 @@ func execute(query, target string, opts int) string {
var buf bytes.Buffer
enc := json.NewEncoder(&buf)
enc.SetEscapeHTML(false)
if opts&optIndent == optIndent {
enc.SetIndent("", " ")
enc.SetIndent("", " ")
if opts&optLocated == optLocated {
_ = optLocated
}
if err := enc.Encode(res); err != nil {
return fmt.Sprintf("Error parsing results: %v", err)
Expand Down

0 comments on commit 49f294c

Please sign in to comment.