Saturday, January 25, 2014

store json into couchdb with curl

file q1.json:
{
    "type": "quote",
    "author": "Thomas Hardy",
    "text": "And as the smart ship grew
In stature, grace, and hue
In shadowy silent distance grew the Iceberg too.", "work": { "title": "The Convergence Of The Twain", "link": "http://www.poetryfoundation.org/poem/176678", "year": 1915 } }
curl -u user:passwd -X POST http://localhost:5984/example -H 'Content-Type: application/json' -d @q1.json

2 comments:

Anonymous said...

Hi.
Where do I have to place my json file?
I tried to upload a json file from my desktop (Mac) but no data or values were loaded into the document.

I used the same line code as you did.

Thanks

Alex Greif said...

as far as I know, it should be like this

the json file can be anywhere, the shell can find it:
- if you, with your prompt, are in the same folder as the file then its is: -d @q1.json
- if the file is one up in the folder hierarchy then: -d @../q1.json
- or you work with absolute paths like -d @˜/Desktop/q1.json

Alex.