title: JSON object parsing with PHP in bash
body: <p>I tried to parse JSON object with PHP in bash.</p>
  
  <pre><code>{
      "department": {
          "name": "MyDepartment",
          "emp_no": 10
      }
  }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>#!/bin/sh
  key=department-&gt;name
  jsonbody=./object.json
  
  value=$(php -r "\$obj = json_decode(utf8_encode(file_get_contents('$jsonbody')));print \$obj-&gt;'$key';")
  </code></pre>
  
  <p>I got the error message as below. How can handle JSON object with bash variable?</p>
  
  <pre><code>PHP Parse error:  syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or '{' or '$' in Command line code on line 1
  </code></pre>