Unusual syntax JSON parse problem String (Clojure)

后端 未结 2 753
情深已故
情深已故 2021-01-25 07:42

I have a long clojure String (java.lang.String) representing a JSON. It has \"normal\" looking syntax like so:

\"{ a:1, b:\"hello\" }\"

The key

2条回答
  •  爱一瞬间的悲伤
    2021-01-25 08:06

    Depending on your level of desperation, the Groovy JSON Slurper can read this "JSON" in the LAX setting (which allows those attributes, comments, ...)

    Add the following dep:

    [org.codehaus.groovy/groovy-json "2.5.6"]
    

    Then you can run:

    user=> (import [groovy.json JsonSlurper JsonParserType])
    groovy.json.JsonParserType
    user=> (def parser (doto (JsonSlurper.) (.setType JsonParserType/LAX)))
    #'user/parser
    user=> (def data (.parseText parser "{ a:1, b:\"hello\" }"))
    #'user/data
    user=> data
    {"a" 1, "b" "hello"}
    

提交回复
热议问题