title: Parse or view JSON data fields using JQ tool utility where field names have a "-" dash in the key name
body: <p>I have a JSON data file (as shown below) and I'm trying to find field values using <a href="https://stedolan.github.io/jq/tutorial/" rel="nofollow noreferrer">jq</a> utility. </p>
  
  <p>It's working fine except for fields if the key name contains a <code>-</code> dash character in it. </p>
  
  <p>How can I get the values of "<strong>field-2</strong>", "<strong>field-three</strong>" or "<strong>field-three.url</strong>" for element under <code>content.book1</code> (using <code>jq</code> at least)?</p>
  
  <p>I tried the following to get the values but it's giving me the following errors for fields whose key name contains a dash <code>-</code> in it's name. I tried to back slash <code>-</code> character but that didn't help either.</p>
  
  <h1><strong>Error types found:</strong></h1>
  
  <pre><code>jq: error (at &lt;stdin&gt;:27): null (null) and number (2) cannot be subtracted
  jq: 1 compile error
  
  jq: error: three/0 is not defined at &lt;top-level&gt;
  
  jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at &lt;top-level&gt;
  
  jq: error: syntax error, unexpected INVALID_CHARACTER, expecting FORMAT or QQSTRING_START (Unix shell quoting issues?) at &lt;top-level&gt;, line 1:
  </code></pre>
  
  <p>Commands:</p>
  
  <pre><code>$ cat /tmp/my.data.json
  {
    "pages": {
      "book1": [
        "page1",
        "page2-para1",
        "page3-para1-sentence1",
        "page3-para2-sentence3-word4"
      ]
    },
    "content": {
      "book1": {
        "name": "giga",
        "url": "-",
        "field1": "value1",
        "field-2": "value-2",
        "field-three": {
          "name": "THIRD",
          "url": "book1/field-three/",
          "short-url": "book1/field-three/chota-chetan"
        },
        "authur": {
          "name": "lori CHUCK",
          "displayIndex": 4
        },
        "route": "/in-gc/hindi-chini-bhai-bhai"
      }
    }
  }
  
  $ cat /tmp/my.data.json| jq ".pages"
  {
    "book1": [
      "page1",
      "page2-para1",
      "page3-para1-sentence1",
      "page3-para2-sentence3-word4"
    ]
  }
  
  $ cat /tmp/my.data.json| jq ".pages.book1[0]"
  "page1"
  
  $ cat /tmp/my.data.json| jq ".pages.book1[1]"
  "page2-para1"
  
  $ cat /tmp/my.data.json| jq ".content"
  {
    "book1": {
      "name": "giga",
      "url": "-",
      "field1": "value1",
      "field-2": "value-2",
      "field-three": {
        "name": "THIRD",
        "url": "book1/field-three/"
      },
      "authur": {
        "name": "lori CHUCK",
        "displayIndex": 4
      },
      "route": "/in-gc/hindi-chini-bhai-bhai"
    }
  }
  
  $ cat /tmp/my.data.json| jq ".content.book1"
  {
    "name": "giga",
    "url": "-",
    "field1": "value1",
    "field-2": "value-2",
    "field-three": {
      "name": "THIRD",
      "url": "book1/field-three/"
    },
    "authur": {
      "name": "lori CHUCK",
      "displayIndex": 4
    },
    "route": "/in-gc/hindi-chini-bhai-bhai"
  }
  
  $ cat /tmp/my.data.json| jq ".content.book1.name"
  "giga"
  
  $ cat /tmp/my.data.json| jq ".content.book1.field1"
  "value1"
  
  $ cat /tmp/my.data.json| jq ".content.book1.field-2"
  jq: error (at &lt;stdin&gt;:27): null (null) and number (2) cannot be subtracted
  
  $ cat /tmp/my.data.json| jq ".content.book1.field-three"
  jq: error: three/0 is not defined at &lt;top-level&gt;, line 1:
  .content.book1.field-three
  jq: 1 compile error
  
  $ cat /tmp/my.data.json| jq ".content.book1.field-three.url"
  jq: error: three/0 is not defined at &lt;top-level&gt;, line 1:
  .content.book1.field-three.url
  jq: 1 compile error
  
  $ cat /tmp/my.data.json| jq ".content.book1.field\-2"       
  jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at &lt;top-level&gt;, line 1:
  .content.book1.field\-2                    
  jq: 1 compile error
  
  $ cat /tmp/my.data.json| jq ".content.book1.field\\-2"
  jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at &lt;top-level&gt;, line 1:
  .content.book1.field\-2                    
  jq: 1 compile error
  
  $ cat /tmp/my.data.json| jq ".content.book1.'field-2'"
  jq: error: syntax error, unexpected INVALID_CHARACTER, expecting FORMAT or QQSTRING_START (Unix shell quoting issues?) at &lt;top-level&gt;, line 1:
  .content.book1.'field-2'               
  jq: 1 compile error
  
  $ cat /tmp/my.data.json| jq ".content.book1.authur"
  {
    "name": "lori CHUCK",
    "displayIndex": 4
  }
  
  $ cat /tmp/my.data.json| jq ".content.book1.route"
  "/in-gc/hindi-chini-bhai-bhai"
  
  $
  </code></pre>
  
  <p><strong>PS:</strong> 
  I already know <code>egrep</code> so that's not what I'm looking for.</p>
  
  <pre><code>cat /tmp/my.data.json| jq ".content.book1"|egrep "short-url|field-2"
    "field-2": "value-2",
      "short-url": "book1/field-three/chota-chetan"
  </code></pre>
  
  <p>and
  someone really did a great job here: <a href="https://jqplay.org/" rel="nofollow noreferrer">https://jqplay.org/</a></p>