Error about 'invalid JSON' with couchDB view but the json's fine

后端 未结 4 907
故里飘歌
故里飘歌 2021-02-04 13:31

I am trying to setup the following view on CouchDB

{
\"_id\":\"_design/id\",
\"_rev\":\"1-9be2e55e05ac368da3047841f301203d\",
\"language\":\"javascript\",
    \"         


        
相关标签:
4条回答
  • 2021-02-04 13:45

    It might be necessary to put your JSON into single quotes:

    curl -vX PUT http://localhost:5984/dbname/docid -d '{"foo" : "bar"}'
    

    works for me but

    curl -vX PUT http://localhost:5984/dbname/docid -d {"foo" : "bar"}
    

    throws the error you mention. I guess the shell somehow interferes with the data you send when you omit the single quotes.

    edit: I'm using bash.

    0 讨论(0)
  • 2021-02-04 13:46

    Did you update CouchDB from source recently? If so, be sure to remove all old files.

    0 讨论(0)
  • 2021-02-04 13:56

    @titanoba hinted at the problem:

    The -d option of curl expects the actual data as the argument!

    If you want to provide the data in a file, you need to prefix it with @:

    curl -X PUT -d @keys.json  $CDB/_design/id
    
    0 讨论(0)
  • 2021-02-04 13:56

    The reason

    curl -vX PUT http://localhost:5984/dbname/docid -d {"foo" : "bar"}
    

    Doesn't work is that the quotes are interpolated by the shell using the single quotes escapes the quotes.

    0 讨论(0)
提交回复
热议问题