Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows: curl with json data on the command line

I am running the following command in Windows prompt:

curl -XPUT http://127.0.0.1:9200/test-index/test-type/_mapping?pretty=true -d '{"test-type": {"properties": {"name": {"index": "analyzed", "term_vector": "with_positions_offsets", "boost": 1.0, "store": "yes", "type": "string"}}}}'

I get the following error:

{
  "error" : "ElasticsearchParseException[Failed to parse content to map]; nested: JsonParseException[Unexpected character (''' (code 39)): expected a
valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.elasticsearch.common.compress.lzf.LZFCompressedStreamInput@45
4ed1d2; line: 1, column: 2]]; ",
  "status" : 400
}

I searched for solutions and found alternatives such as put json data in files, but I cannot use it for some reasons.

Thanks!

like image 602
curious1 Avatar asked Feb 21 '15 17:02

curious1


2 Answers

Windows's cmd doesn't support strings with single quotes. Use " and escape the inner ones with \".

like image 148
Daniel A. White Avatar answered Oct 23 '22 18:10

Daniel A. White


"I searched for solutions and found alternatives such as put json data in files, but I cannot use it for some reasons"

This should work, with hello.json in temp. The @ is requried.

c:\temp>curl -v -X PUT  \ 
             --data "@hello.json"  \
             -H "Content-Type:application/json"  \
             http://localhost:8080/api/myresource
like image 24
Paul Samsotha Avatar answered Oct 23 '22 19:10

Paul Samsotha