> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JSON Egress

> Copy-paste examples of retrieving JSON data with the /get/records/json endpoint

The [/get/records/json](/content/api/rest/get_records_json_rest) REST
endpoint can be called to retrieve data in JSON form directly from the database.

See [Overview](/content/api/rest/get_records_json_rest) for call details
and [Responses](/content/api/rest/get_records_json_rest#get-records-json-response) for return values.

## Simple Egress

<CodeGroup>
  ```bash cURL theme={null}
  KINETICA_URL=http://localhost:9191
  USERNAME=auser
  PASSWORD=apassword
  TABLE_NAME=product

  # Quote the URL when passing multiple options, or any & will stop the URL
  #   parsing and run the URL parsed up to that point as a background job
  curl -sS ${KINETICA_URL}/get/records/json?table_name=${TABLE_NAME} \
  --header "Content-Type: application/json" \
  --user "${USERNAME}:${PASSWORD}"
  ```

  ```python Python theme={null}
  kinetica_url = "http://localhost:9191"
  username = "auser"
  password = "apassword"
  kinetica = gpudb.GPUdb([kinetica_url], username = username, password = password)

  table_name = "example.product"
  order = None

  response = kinetica.get_records_json(table_name, orderby_columns = order)
  ```

  ```java Java theme={null}
  String url = "http://localhost:9191"
  GPUdb.Options options = new GPUdb.Options();
  options.setUsername(username);
  options.setPassword(password);
  GPUdb kdb = new GPUdb(url, options);

  String tableName = "product";

  GetRecordsJsonResponse response = kdb.getRecordsJson(tableName, null, 0, GPUdb.END_OF_SET);
  ```

  ```javascript JavaScript theme={null}
  const kinetica_url = 'http://localhost:9191'
  const username = 'auser'
  const password = 'apassword'
  const db = new GPUdb([kinetica_url], {'username': username, 'password': password});

  let tableName = 'product';
  let order = [];

  db.get_records_json(tableName, [], 0, GPUdb.END_OF_SET, null, order, null, (err,  response) => {
  	if (err)
  		console.error(err);
  	else
  		console.info("All records:");
  		response.records.forEach(element => {
  			console.info(element);
  		});
  });
  ```

  ```javascript Node.js theme={null}
  const kinetica_url = 'http://localhost:9191'
  const username = 'auser'
  const password = 'apassword'
  const db = new GPUdb([kinetica_url], {'username': username, 'password': password});

  let tableName = 'product';
  let order = [];

  db.get_records_json(tableName, [], 0, GPUdb.END_OF_SET, null, order, null, (err,  response) => {
  	if (err)
  		console.error(err);
  	else
  		console.info("All records:");
  		response.records.forEach(element => {
  			console.info(element);
  		});
  });
  ```
</CodeGroup>

## Egress with Parameters

<CodeGroup>
  ```bash cURL theme={null}
  KINETICA_URL=http://localhost:9191
  USERNAME=auser
  PASSWORD=apassword
  TABLE_NAME=product

  # Using data-urlencode can make params easier to read than appending to URL
  #   Use the G option to pass the data-urlencode options as GET query parameters
  curl -sSG ${KINETICA_URL}/get/records/json \
  --header "Content-Type: application/json" \
  --user "${USERNAME}:${PASSWORD}" \
  --data-urlencode "table_name=${TABLE_NAME}" \
  --data-urlencode "column_names=name,category,description,stock" \
  --data-urlencode "expression=stock > 100000" \
  --data-urlencode "order_by=name"
  ```

  ```python Python theme={null}
  kinetica_url = "http://localhost:9191"
  username = "auser"
  password = "apassword"
  kinetica = gpudb.GPUdb([kinetica_url], username = username, password = password)

  table_name = "example.product"
  column_names = ["name", "category", "description", "stock"]
  expr = "stock > 100000"
  order = ["name"]

  response = kinetica.get_records_json(table_name, column_names, expression = expr, orderby_columns = order)
  ```

  ```java Java theme={null}
  String url = "http://localhost:9191"
  GPUdb.Options options = new GPUdb.Options();
  options.setUsername(username);
  options.setPassword(password);
  GPUdb kdb = new GPUdb(url, options);

  String tableName = "product";
  List<String> columnNames = GPUdb.list("name", "category", "description", "stock");
  String expression = "stock > 100000";
  List<String> order = GPUdb.list("name");

  GetRecordsJsonResponse response =
          kdb.getRecordsJson(tableName, columnNames, 0, GPUdb.END_OF_SET, expression, order);
  ```

  ```javascript JavaScript theme={null}
  const kinetica_url = 'http://localhost:9191'
  const username = 'auser'
  const password = 'apassword'
  const db = new GPUdb([kinetica_url], {'username': username, 'password': password});

  let tableName = 'product';
  const columnNames = ['name', 'category', 'description', 'stock'];
  const expression = 'stock > 100000';
  const order = ['name'];

  db.get_records_json(tableName, columnNames, 0, GPUdb.END_OF_SET, expression, order, null, (err,  response) => {
  	if (err)
  		console.error(err);
  	else
  		console.info("Filtered records:");
  		response.records.forEach(element => {
  			console.info(element);
  		});
  });
  ```

  ```javascript Node.js theme={null}
  const kinetica_url = 'http://localhost:9191'
  const username = 'auser'
  const password = 'apassword'
  const db = new GPUdb([kinetica_url], {'username': username, 'password': password});

  let tableName = 'product';
  const columnNames = ['name', 'category', 'description', 'stock'];
  const expression = 'stock > 100000';
  const order = ['name'];

  db.get_records_json(tableName, columnNames, 0, GPUdb.END_OF_SET, expression, order, null, (err,  response) => {
  	if (err)
  		console.error(err);
  	else
  		console.info("Filtered records:");
  		response.records.forEach(element => {
  			console.info(element);
  		});
  });
  ```
</CodeGroup>

## Egress with Aggregation

<CodeGroup>
  ```bash cURL theme={null}
  KINETICA_URL=http://localhost:9191
  USERNAME=auser
  PASSWORD=apassword
  TABLE_NAME=product

  # Using data-urlencode can make params easier to read than appending to URL
  #   Use the G option to pass the data-urlencode options as GET query parameters
  curl -sSG ${KINETICA_URL}/get/records/json \
  --header "Content-Type: application/json" \
  --user "${USERNAME}:${PASSWORD}" \
  --data-urlencode "table_name=${TABLE_NAME}" \
  --data-urlencode "column_names=category,COUNT(1) AS total_products" \
  --data-urlencode "expression=stock >= 1000" \
  --data-urlencode "having=COUNT(1) > 1"
  ```

  ```python Python theme={null}
  kinetica_url = "http://localhost:9191"
  username = "auser"
  password = "apassword"
  kinetica = gpudb.GPUdb([kinetica_url], username = username, password = password)

  table_name = "example.product"
  column_names = ["category", "COUNT(1) AS total_products"]
  expr = "stock >= 1000"
  having = "COUNT(1) > 1"

  response = kinetica.get_records_json(table_name, column_names, expression = expr, having_clause = having)
  ```

  ```java Java theme={null}
  String url = "http://localhost:9191"
  GPUdb.Options options = new GPUdb.Options();
  options.setUsername(username);
  options.setPassword(password);
  GPUdb kdb = new GPUdb(url, options);

  String tableName = "product";
  List<String> columnNames = GPUdb.list("category", "COUNT(1) AS total_products");
  String expression = "stock > 1000";
  String having = "COUNT(1) > 1";

  GetRecordsJsonResponse response =
          kdb.getRecordsJson(tableName, columnNames, 0, GPUdb.END_OF_SET, expression, having);
  ```

  ```javascript JavaScript theme={null}
  const kinetica_url = 'http://localhost:9191'
  const username = 'auser'
  const password = 'apassword'
  const db = new GPUdb([kinetica_url], {'username': username, 'password': password});

  let tableName = 'product';
  const columnNames = ['category', 'COUNT(1) AS total_products'];
  const expression = 'stock >= 1000';
  const having = 'COUNT(1) > 1';
  const order = [];

  db.get_records_json(tableName, columnNames, 0, GPUdb.END_OF_SET, expression, order, having, (err,  response) => {
  	if (err)
  		console.error(err);
  	else
  		console.info("Aggregated records:");
  		response.records.forEach(element => {
  			console.info(element);
  		});
  });
  ```

  ```javascript Node.js theme={null}
  const kinetica_url = 'http://localhost:9191'
  const username = 'auser'
  const password = 'apassword'
  const db = new GPUdb([kinetica_url], {'username': username, 'password': password});

  let tableName = 'product';
  const columnNames = ['category', 'COUNT(1) AS total_products'];
  const expression = 'stock >= 1000';
  const having = 'COUNT(1) > 1';
  const order = [];

  db.get_records_json(tableName, columnNames, 0, GPUdb.END_OF_SET, expression, order, having, (err,  response) => {
  	if (err)
  		console.error(err);
  	else
  		console.info("Aggregated records:");
  		response.records.forEach(element => {
  			console.info(element);
  		});
  });
  ```
</CodeGroup>
