# C1.DataEngine.QueryFactory.CreateQueryFromJsonString

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_DataEngine_QueryFactory_CreateQueryFromJsonString_" data-uid="C1.DataEngine.QueryFactory.CreateQueryFromJsonString*">CreateQueryFromJsonString Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_DataEngine_QueryFactory_CreateQueryFromJsonString_" data-uid="C1.DataEngine.QueryFactory.CreateQueryFromJsonString*"></a>
<h4 id="C1_DataEngine_QueryFactory_CreateQueryFromJsonString_C1_DataEngine_Workspace_System_String_" data-uid="C1.DataEngine.QueryFactory.CreateQueryFromJsonString(C1.DataEngine.Workspace,System.String)">CreateQueryFromJsonString(Workspace, string)</h4>
<div class="markdown level1 summary"><p>Creates a C1DataEngine query from a JSON string.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public static object CreateQueryFromJsonString(Workspace workspace, string json)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Shared Function CreateQueryFromJsonString(workspace As Workspace, json As String) As Object</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="../C1.DataEngine/C1.DataEngine.Workspace.html">Workspace</a></td>
      <td><span class="parametername">workspace</span></td>
      <td><p>The C1DataEngine <a class="xref" href="../C1.DataEngine/C1.DataEngine.Workspace.html">Workspace</a> object in which the query will be created.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></td>
      <td><span class="parametername">json</span></td>
      <td><p>The JSON string that describes query elements such as tables, columns, and range conditions.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></td>
      <td><p>A dynamic object representing the query. The caller is responsible for executing it.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_DataEngine_QueryFactory_CreateQueryFromJsonString_C1_DataEngine_Workspace_System_String__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>Typically, queries are created in C# code using anonymous objects, as in the following example:</p>
<pre><code class="lang-csharp">dynamic products = workspace.table("Products");
dynamic query = workspace.query("ProductsByColor", new {
    products.ProductColor,
    Count = Op.Count(products.ProductID),
    _range = products.ProductPrice.Gte(100)
});
query.Query.Execute();</code></pre>
<p>Applications that allow end users to create ad-hoc queries can use this method to create a query from a JSON string:</p>
<pre><code class="lang-csharp">string json = @"{
  "name": "ProductsByColor",
  "tables": [
    "Products"
  ],
  "columns": [
    { "names": [ "ProductColor" ] },
    {
      "names": [ "ProductID" ],
      "op": "Count",
      "alias": "Count"
    }
  ],
  "range": [
    { "name": "ProductPrice",
      "expr": [
        { "op": "Gte", "value": "100" }
      ]
    }
  ]
}";
dynamic query = CreateQueryFromJsonString(workspace, json);
query.Query.Execute();</code></pre>
</div>
</div>
