title: advanced JSON query language
body: <p>I've explored couple of existing JSON query language such <a href="https://jmespath.org/specification.html" rel="nofollow noreferrer">JMESPath</a>, <a href="https://github.com/json-path/JsonPath" rel="nofollow noreferrer">JsonPath</a> and <a href="http://www.jsoniq.org/" rel="nofollow noreferrer">JSONiq</a>. Unfortunately, none of them seem to be able to support my use case in a generic way.</p>
  
  <p>Basically, I'm receiving different type of responses from different web services. I need to give the ability to the user to remap the response in a 2 dimensional array in other to leverage our visualization tool. Based on the new format, the user can decide how to display his data between existing widgets. Pretty much like a customisable dashboard entirely managed on the UI. </p>
  
  <p>Anyway my input looks like:</p>
  
  <pre><code>{
    "category_1": [
      {
        "name": "medium",
        "count": 10
      },
      {
        "name": "high",
        "count": 20
      }
    ],
    "category_2": [
      {
        "name": "medium",
        "count": 30
      },
      {
        "name": "high",
        "count": 40
      }
    ]
  }
  
  </code></pre>
  
  <p>expected output:</p>
  
  <pre><code>[
    {
      "name": "medium",
      "count": 10,
      "category": "1"
    },
    {
      "name": "high",
      "count": 20,
      "category": "1"
    },
    {
      "name": "medium",
      "count": 30,
      "category": "2"
    },
    {
      "name": "high",
      "count": 40,
      "category": "2"
    }
  ]
  </code></pre>
  
  <p>The closer I went is with JMESPath but my query isn't dynamic at all. The user needs to be aware of possible category of grouping.</p>
  
  <p>The query looks like: <code>[ category_1[].{name: name, count: count, category: '1'}, category_2[].{name: name, count: count, category: '2'} ] | []</code></p>
  
  <p>In other words, I need an enough powerful JSON query language to perform this JavaScript code:</p>
  
  <pre><code>const output = flatMap(input, (value, key) =&gt; {
    return value.map(x =&gt; {
      return { ...x, category: key };
    });
  });
  
  </code></pre>
  
  <p>Any thoughts?</p>