20

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?

4

2 Answers 2

20

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

Sign up to request clarification or add additional context in comments.

Comments

11

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 

3 Comments

Since --data implies a POST method, "-X POST" can be removed from the command line.
@DanielStenberg true, but explicitness is better IMO.
Some call it explicit, I call it misleading and error-prone: daniel.haxx.se/blog/2015/09/11/unnecessary-use-of-curl-x

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.