Skip to content

json-var: NGINX JSON variables module


CentOS/RHEL 6, 7, 8 or Amazon Linux 2

bash yum -y install yum -y install nginx-module-json-var

Enable the module by adding the following at the top of /etc/nginx/nginx.conf:

nginx load_module modules/;

This document describes nginx-module-json-var v1.1 released on Feb 11 2022.

Adds the ability to group Nginx variable expressions as json.



  • syntax: json_var $variable { ... }
  • default: none
  • context: http

Creates a new variable whose value is a json containing the items listed within the block. Parameters inside the json_var block specify a field that should be included in the resulting json. Each parameter has to contain two arguments - key and value. The value can contain nginx variables.

Sample configuration

```nginx http { json_var $output { timestamp $time_local; remoteAddr $remote_addr; xForwardedFor $http_x_forwarded_for; userAgent $http_user_agent; params $args; }

server {
    location /get_json/ {
        return 200 $output;

Hitting `http://domain/get_json/?key1=value1&key2=value2` can return a json like: { "timestamp": "21/Jul/2017:12:44:18 -0400", "remoteAddr": "", "xForwardedFor": "", "userAgent": "curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/ libidn/1.23 librtmp/2.3", "params": "key1=value1&key2=value2" } ```

All code in this project is released under the AGPLv3 license unless a different license for a particular library is specified in the applicable library path.

Copyright © Kaltura Inc. All rights reserved.


You may find additional configuration tips and documentation for this module in the GitHub repository for nginx-module-json-var.

Back to top