17

I'm not sure if this is possible, but i am trying to curl a post, but with a json as the parameters, like such:

curl -X POST 'https://myserver/action?params={"field1":"something","whatever":10,"description":"body","id":"random","__oh__":{"session":"12345678jhgfdrtyui"}}'

however, i keep getting some error curl: (3) [globbing] nested braces not supported at pos X

how do i do this?

user2864740
  • 54,112
  • 10
  • 112
  • 187
David T.
  • 18,561
  • 18
  • 61
  • 115
  • 1
    http://stackoverflow.com/questions/7172784/how-to-post-json-data-with-curl-from-terminal-commandline-to-test-spring-rest – user32342534 Aug 21 '14 at 21:00
  • @user32342534 i'm not sure i understand correctly - but that other question is talking about sending json inside the body of the request? what if i want to add json as part of the request url parameters? or are you saying that they are the same exactly thing? – David T. Aug 21 '14 at 21:33
  • In case of the `Instagram` API it is not the same thing, but mentally for me it is! https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Sending_and_retrieving_form_data – user32342534 Aug 22 '14 at 03:48
  • `GET` sends the data via the URL, `POST` sends the data in the message body: http://docs.aws.amazon.com/AWSImportExport/latest/DG/SamplePOSTRequest.html. Same encoding style. More: http://stackoverflow.com/questions/3477333/what-is-the-difference-between-post-and-get. – user32342534 Aug 22 '14 at 04:09

2 Answers2

19

The curl error is due to braces {} and square brackets [] being special curl globbing characters. Use the -g option to turn off globbing and you should be fine.

Same issue as this post: How to PUT a json object with an array using curl

Community
  • 1
  • 1
Yonik
  • 2,181
  • 17
  • 14
8

There two ways to approach this.

  1. Ensure that your JSON is properly escaped so that it can be sent as a parameter.
  2. Set the HTTP header to accept json.

For example:

curl -X POST -H "Content-Type: application/json" \
--data '{"field1":"something","whatever":10,"description":"body","id":"random","__oh__":{"session":"12345678jhgfdrtyui"}}' \
https://example.com/action
Martin Konecny
  • 50,691
  • 18
  • 119
  • 145