How to cURL post with JSON parameters?

39,854

Solution 1

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

Solution 2

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
Share:
39,854
David T.
Author by

David T.

Junior Android developer coming here on Stack Overflow to improve my coding abilities game dev experience (iOS, Android & OUYA + others)

Updated on May 25, 2020

Comments

  • David T.
    David T. almost 4 years

    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?