Skip to content

add a json string macro #10

Description

@hellerve

typing complex json literals in carp is annoying.

(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.

(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.

; 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions