# Envoyer variable JSON en batch

**URL:** <https://www.debian-fr.org/t/envoyer-variable-json-en-batch/59857>\
**Category:** Programmation\
**Created:** [Février 21, 2016, 6:42 UTC](https://www.debian-fr.org/t/envoyer-variable-json-en-batch/59857 "2016-02-21T18:42:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_seb](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/_/90db22/32.png) [@\_seb](https://www.debian-fr.org/u/_seb)\
**Post date:** [Février 21, 2016, 6:42 UTC](https://www.debian-fr.org/t/envoyer-variable-json-en-batch/59857/1 "2016-02-21T18:42:57Z")

</div>

Bonjour,

Dans un script bash je construit une variable JSON :

```auto
{
"test": { "val1" : "1", "val2" : "2" },
"date" : "24102013",
"JSON" : "close"
}
```

```auto
VAR=$(cat output.json)
$JSON=$(echo "'$VAR'")
```

J’essaye de l’envoyer à ma page PHP avec wget et curl mais je n’y arrive pas… En fait je bute sur la variable $JSON qui ne doit pas être bien formaté et me donne des erreurs…

> [@](#):
>
> wget -O- $API --header ‹&nbsp;Content-Type: application/json&nbsp;› --post-data $JSON  
> curl -i -H «&nbsp;Content-Type: application/json&nbsp;» -X POST --data $JSON $API

Merci…

---

<div class="post-metadata">

**Author:** ![syam](https://www.debian-fr.org/user_avatar/www.debian-fr.org/syam/32/2951_2.png) [@syam](https://www.debian-fr.org/u/syam)\
**Post date:** [Février 21, 2016, 6:42 UTC](https://www.debian-fr.org/t/envoyer-variable-json-en-batch/59857/2 "2016-02-21T18:42:59Z")

</div>

Faut mettre ta variable entre guillemets pour dire au shell de considérer toute la variable comme un seul argument :

```auto

```

Probablement pareil pour $API (c’est l’URL je suppose).

---

<div class="post-metadata">

**Author:** ![\_seb](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/_/90db22/32.png) [@\_seb](https://www.debian-fr.org/u/_seb)\
**Post date:** [Février 21, 2016, 6:50 UTC](https://www.debian-fr.org/t/envoyer-variable-json-en-batch/59857/3 "2016-02-21T18:50:11Z")

</div>

Bonjour syam,

Oui, tu as complétement raison ![:023](https://www.debian-fr.org/uploads/default/original/1X/3c587556c0cc11389317c03a60788d77ceebd307.gif "OK")
