carpentry-org / carpentry-org/json
add a json string macro
- Dominant language
- Python
- Stars
- 0
- Forks
- 0
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 3
Description
typing complex json literals in carp is annoying.
```clojure
(defn empty-provision []
(JSON.obj [(JSON.entry @"created_fields" (JSON.Arr (the (Array (Box JSON)) [])))
(JSON.entry @"created_tags" (JSON.Arr (the (Array (Box JSON)) [])))]))
```
but the alternative requires a parse.
```clojure
(defn empty-provision []
(Result.unsafe-from-success (JSON.parse "{\"created_fields\": [], \"created_tags\": []}")))
```
which is equally annoying. i’d prefer being able to offload this to compile time, and adding a macro that compiles json literals into a carp expression.
```clojure
; name tbd
(macro-expand (JSON.literal "{\"created_fields\": [], \"created_tags\": []}")))
; expands to
; (JSON.obj [(JSON.entry @"created_fields" (JSON.Arr (the (Array (Box JSON)) [])))
; (JSON.entry @"created_tags" (JSON.Arr (the (Array (Box JSON)) [])))]))
```
nice error checking and good output would be table stakes here.
cheers
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by comparing the JSON.obj and JSON.parse approaches shown in the issue, then investigate how Carp's macro-expand flow can accept a JSON string literal. Done means the literal expands at compile time to the equivalent JSON expression, with useful errors and output for invalid or unsupported JSON.
Written by the indexing model from the issue text.
Assessment
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100