JSON::render

Description

This command returns a string containing a textual rendering of the JSON cache content.
  • If a JSON cache handle is omitted, renders any JSON cache that preexists in the context in which this is executed. This is the normal case when the command is executed in a the JSON_REQUEST or JSON_RESPONSE event.
  • If a JSON cache handle is provided, renders that JSON cache. This is useful when a JSON profile is not being used.

Note

Rendering consumes the data in the cache, so after a render, no further value retrieval/modification/rendering may be done on this JSON cache instance.

Note

If a JSON profile is in use, the JSON cache will be rendered in the message egressed to the receiving connection. Since a JSON cache can only be rendered once, rendering the cache in an iRule will prevent it being rendered on egress, effectively dropping it from the egress message body. In other words, once an iRule takes over the rendering, it is also responsible for providing any JSON content on egress.

Syntax

JSON::render [JSON_CACHE]

Examples

when JSON_REQUEST {
    set rootval [JSON::root]
    JSON::set $rootval string HelloWorld
    set rendered [JSON::render]
    # The message will be returned to the source and will not be sent to the destination.
    HTTP::respond $http_resp_headers $rendered
}
when MR_INGRESS {
    set cache [JSON::create]
    set rootval [JSON::root $cache]
    JSON::set $rootval string HelloWorld
    set rendered [JSON::render $cache]
}