How to parse json file with c-style comments?

后端 未结 5 1342
無奈伤痛
無奈伤痛 2020-12-03 10:19

I have a json file, such as the following:

    { 
       \"author\":\"John\",
       \"desc\": \"If it is important to decode all valid JSON correctly \\ 
an         


        
5条回答
  •  孤城傲影
    2020-12-03 10:21

    How about commentjson?

    http://commentjson.readthedocs.io/en/latest/

    This can parse something like below.

    {
        "name": "Vaidik Kapoor", # Person's name
        "location": "Delhi, India", // Person's location
    
        # Section contains info about
        // person's appearance
        "appearance": {
            "hair_color": "black",
            "eyes_color": "black",
            "height": "6"
        }
    }
    

    Likely elasticsearch, some products' REST API do not accept comment field. Therefore, I think comment inside json is necessary for a client in order to maintain such as a json template.


    EDITED

    jsmin seems to be more common.

    https://pypi.python.org/pypi/jsmin

    • references
      • https://plus.google.com/+DouglasCrockfordEsq/posts/RK8qyGVaGSr
      • Can comments be used in JSON?
      • https://www.quora.com/How-do-I-write-comments-inside-a-JSON-document
      • https://github.com/JetBrains/intellij-community/blob/webstorm/191.6183.63/json/src/com/intellij/json/JsonBundle.properties#L16

提交回复
热议问题