Skip to content

Commit 4043816

Browse files
andreyorstmput
andcommitted
[#6106] proper support for comments in JSON
Co-authored-by: mput <putintsev@gmail.com>
1 parent e772066 commit 4043816

5 files changed

Lines changed: 70 additions & 6 deletions

File tree

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"@monaco-editor/react": "^4.5.0",
66
"@sooro-io/react-gtm-module": "^3.0.0",
77
"antd": "^5.18.3",
8+
"comment-json": "^4.2.5",
89
"fhirpath-autocomplete-ts": "git@github.com:Aidbox/fhirpath-autocomplete-ts.git",
910
"react": "^18.2.0",
1011
"react-dom": "^18.3.1",

src/cljs/vd_designer/pages/form/controller.cljs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,11 @@
435435
{:dataLayer {:event "vd_run"
436436
:resource-type (get (:current-vd db) :resource "")}})
437437
(let [sandbox? (settings-model/in-sandbox? db)
438+
parse (if (= :language/json (::m/language db))
439+
yaml/json-parse
440+
yaml/try-parse)
438441
view-definition (-> (::m/view-definition-code db)
439-
yaml/try-parse
442+
parse
440443
(js->clj :keywordize-keys true)
441444
strip-empty-select-nodes
442445
strip-empty-where-nodes)
@@ -481,7 +484,6 @@
481484
(reg-event-fx
482485
::on-eval-view-definition-error
483486
(fn [{:keys [db]} [_ result]]
484-
(prn result)
485487
{:db (assoc db ::m/eval-loading false)
486488
:notification-error (str (get-in result [:response :text :div] "Error") ": "
487489
(->> (get-in result [:response :issue])
@@ -702,7 +704,7 @@
702704

703705
(defn format-vd-code [code lang]
704706
(case lang
705-
:language/yaml (-> code js/JSON.parse yaml/stringify)
707+
:language/yaml (-> code yaml/json-parse yaml/stringify)
706708
:language/json (-> code yaml/str->yaml (js/JSON.stringify nil 2))
707709
""))
708710

src/cljs/vd_designer/pages/lists/vds/import.cljs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[vd-designer.components.tabs :as tabs]
99
[vd-designer.pages.lists.vds.controller :as c]
1010
[vd-designer.pages.lists.vds.model :as m]
11-
[vd-designer.utils.yaml :refer [str->yaml]]))
11+
[vd-designer.utils.yaml :refer [str->yaml json-parse]]))
1212

1313
(def supported-extensions
1414
[".json" ".yaml" ".yml"])
@@ -34,7 +34,7 @@
3434
(try
3535
(str->yaml content)
3636
(catch js/Error _
37-
(js/JSON.parse content))))
37+
(json-parse content))))
3838

3939
(defn parse-vd [^String content]
4040
(js->clj (try-parse-vd content) :keywordize-keys true))

src/cljs/vd_designer/utils/yaml.cljs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns vd-designer.utils.yaml
22
(:require ["yaml" :as y]
3+
["comment-json" :as json]
34
[clojure.string :as str]))
45

56
(defn edn->yaml [edn]
@@ -18,4 +19,10 @@
1819
(try
1920
(str->yaml content)
2021
(catch js/Error _
21-
(js/JSON.parse content))))
22+
nil)))
23+
24+
(defn json-parse [^String content]
25+
(try
26+
(json/parse content nil true)
27+
(catch js/Error _
28+
nil)))

0 commit comments

Comments
 (0)