Skip to main content
Active reading [<https://en.wikipedia.org/wiki/JSON>]. Expanded.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

You can catcat the contents of a jsonJSON file to curl via the --data-raw parameter.

curl 'https://api.com/route' -H 'Content-Type: application/json' --data-raw "$(cat ~/.json/payload-2022-03-03.json | grep -v '^\s*//')"

Note: comments in the jsonJSON file are filtered out via grep -v '^\s*//'

You can also pass the data to curl via stdinstandard input using grep or cat.

grep -v '^\s*//' ~/.json/payload-2022-03-03.json | curl 'https://api.com/route' -H 'Content-Type: application/json' -d @-

cat ~/.json/payload-2022-03-03.json | grep -v '^\s*//' | curl 'https://api.com/route' -H 'Content-Type: application/json' -d @-

You can cat the contents of a json file to curl via the --data-raw parameter

curl 'https://api.com/route' -H 'Content-Type: application/json' --data-raw "$(cat ~/.json/payload-2022-03-03.json | grep -v '^\s*//')"

Note: comments in the json file are filtered out via grep -v '^\s*//'

You can also pass the data to curl via stdin using grep or cat

grep -v '^\s*//' ~/.json/payload-2022-03-03.json | curl 'https://api.com/route' -H 'Content-Type: application/json' -d @-

cat ~/.json/payload-2022-03-03.json | grep -v '^\s*//' | curl 'https://api.com/route' -H 'Content-Type: application/json' -d @-

You can cat the contents of a JSON file to curl via the --data-raw parameter.

curl 'https://api.com/route' -H 'Content-Type: application/json' --data-raw "$(cat ~/.json/payload-2022-03-03.json | grep -v '^\s*//')"

Note: comments in the JSON file are filtered out via grep -v '^\s*//'

You can also pass the data to curl via standard input using grep or cat.

grep -v '^\s*//' ~/.json/payload-2022-03-03.json | curl 'https://api.com/route' -H 'Content-Type: application/json' -d @-

cat ~/.json/payload-2022-03-03.json | grep -v '^\s*//' | curl 'https://api.com/route' -H 'Content-Type: application/json' -d @-

Source Link
Andrew
  • 4k
  • 1
  • 37
  • 40

You can cat the contents of a json file to curl via the --data-raw parameter

curl 'https://api.com/route' -H 'Content-Type: application/json' --data-raw "$(cat ~/.json/payload-2022-03-03.json | grep -v '^\s*//')"

Note: comments in the json file are filtered out via grep -v '^\s*//'

You can also pass the data to curl via stdin using grep or cat

grep -v '^\s*//' ~/.json/payload-2022-03-03.json | curl 'https://api.com/route' -H 'Content-Type: application/json' -d @-

cat ~/.json/payload-2022-03-03.json | grep -v '^\s*//' | curl 'https://api.com/route' -H 'Content-Type: application/json' -d @-