title: Replacing underscores in JSON using JQ
body: <p>I'm working with the <a href="http://woocommerce.github.io/woocommerce-rest-api-docs/" rel="noreferrer">woocommerce</a> API to retrieve and store information. Currently our setup is designed to use camel case instead of underscores. I'm using <code>jq</code> to process our information, but I'm curious how I can use the <code>sub(regex, tostring)</code> function to replace the underscores in my JSON with camelCase?</p>
  
  <p>Here's an example of the code</p>
  
  <pre><code>"line_items": [
      {
       "id": xxxx,
       "name": "xxxx",
       "sku": "xxxx",
       "product_id": xxxx,
      }
  </code></pre>
  
  <p>For example, according to another answer on SO that I found, this works: <code>curl https://www.testsite.com/wp-json/wc/v1/orders -u user:pass | jq '.[] | with_entries( if .key | contains("_") then .key |= sub("_";"") else . end)'</code> and remove the underscores.</p>
  
  <p>The result is:</p>
  
  <pre><code>"lineitems": [
      {
       "id": xxxx,
       "name": "xxxx",
       "sku": "xxxx",
       "productid": xxxx,
      }
  </code></pre>
  
  <p>However, when I try <code>curl https://www.testsite.com/wp-json/wc/v1/orders -u user:pass | jq '.[] | with_entries( if .key | contains("_") then .key |= sub("(\\_)([a-z])";"$2\u") else . end)'</code> I don't get the results I would expect.</p>
  
  <p>The expected results would be:</p>
  
  <pre><code>"lineItems": [
      {
       "id": xxxx,
       "name": "xxxx",
       "sku": "xxxx",
       "productId": xxxx,
      }
  </code></pre>
  
  <p>I don't have a lot of experience using <code>jq</code> so I'm not sure what I'm doing wrong. Is there a better solution to this problem?</p>