There are basically two ways.
Give the JSON payload to jq as a string:
$ jq -n --arg rec '{ "id": 1, "name": "x"}' '$ARGS.named' { "rec": "{ \"id\": 1, \"name\": \"x\"}" }
Note that jq will not validate the supplied string in any way and will preserve it as it was, excessive whitespace and all.
Give jq the payload as an input JSON document and use tojson to stringify it:
$ jq -n --argjson payload '{ "id": 1, "name": "x"}' '.rec = ($payload|tojson)' { "rec": "{\"id\":1,\"name\":\"x\"}" }
Here, jq would complain if the given JSON fragment was invalid, and it also "compresses" it by removing unnecessary whitespace.
The same thing, but reading from standard input:
$ echo '{ "id": 1, "name": "x"}' | jq -n '.rec = (inputs|tojson)' { "rec": "{\"id\":1,\"name\":\"x\"}" }
The difference between input and inputs is that input reads a single object from the input of jq, while inputs read all remaining objects.
Or, since it's shorter, pull the input directly into tojson by removing the -n/--null-input option:
$ echo '{ "id": 1, "name": "x"}' | jq '{ rec: tojson }' { "rec": "{\"id\":1,\"name\":\"x\"}" }
This would slurp all data from the input of jq (just like when using inputs, with -n) and insert it as the value of the rec key, via tojson.
To do the opposite, i.e., to decode the stringified payload, use fromjson:
$ echo '{"rec":"{\"id\":1,\"name\":\"x\"}"}' | jq '.rec | fromjson' { "id": 1, "name": "x" }
$ jq -n --argjson doc '{"rec":"{\"id\":1,\"name\":\"x\"}"}' '$doc.rec | fromjson' { "id": 1, "name": "x" }
Note that echo, in general, isn't the best utility for passing JSON documents to jq (or to anywhere else, for that matter), as depending on your shell and its configuration, it may choose to expand strings like \n and \t to literal newlines and tabs, which would break the formatting of the provided document.