{"action":"created","issue":{"url":"https://api.github.com/repos/stedolan/jq/issues/941","labels_url":"https://api.github.com/repos/stedolan/jq/issues/941/labels{/name}","comments_url":"https://api.github.com/repos/stedolan/jq/issues/941/comments","events_url":"https://api.github.com/repos/stedolan/jq/issues/941/events","html_url":"https://github.com/stedolan/jq/issues/941","id":105287917,"number":941,"title":"Count length in bytes in UTF8 (or arbitrary encoding)","user":{"login":"jnothman","id":78827,"avatar_url":"https://avatars.githubusercontent.com/u/78827?v=3","gravatar_id":"","url":"https://api.github.com/users/jnothman","html_url":"https://github.com/jnothman","followers_url":"https://api.github.com/users/jnothman/followers","following_url":"https://api.github.com/users/jnothman/following{/other_user}","gists_url":"https://api.github.com/users/jnothman/gists{/gist_id}","starred_url":"https://api.github.com/users/jnothman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jnothman/subscriptions","organizations_url":"https://api.github.com/users/jnothman/orgs","repos_url":"https://api.github.com/users/jnothman/repos","events_url":"https://api.github.com/users/jnothman/events{/privacy}","received_events_url":"https://api.github.com/users/jnothman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-08T02:20:30Z","updated_at":"2015-09-08T03:54:57Z","closed_at":null,"body":"I was hoping to use `jq` to transform some JSON records into [redis](http://redis.io) [`APPEND`](redis.io/commands/append) commands (to produce json-seq entries), via its [`redis-cli --pipe` mass-insertion protocol](redis.io/topics/mass-insert). This involves formatting a string in which each argument is prefixed by its length in bytes. `length`, however, only counts the number of Unicode characters. Seeing as strings are output in UTF8, a function to calculate the number of bytes in UTF8 would be valuable so I can construct a redis command as follows:\r\n```\r\njq -j '(tostring | \"\\u001e\\(.)\\n\") as $blob | \"*3\\r\\n$6\\r\\nAPPEND\\r\\n$\\(.key | byteslength)\\r\\n\\(.key)\\r\\n$\\($blob | byteslength)\\r\\n\\($blob)\\r\\n\"'\r\n```"},"comment":{"url":"https://api.github.com/repos/stedolan/jq/issues/comments/138423724","html_url":"https://github.com/stedolan/jq/issues/941#issuecomment-138423724","issue_url":"https://api.github.com/repos/stedolan/jq/issues/941","id":138423724,"user":{"login":"jnothman","id":78827,"avatar_url":"https://avatars.githubusercontent.com/u/78827?v=3","gravatar_id":"","url":"https://api.github.com/users/jnothman","html_url":"https://github.com/jnothman","followers_url":"https://api.github.com/users/jnothman/followers","following_url":"https://api.github.com/users/jnothman/following{/other_user}","gists_url":"https://api.github.com/users/jnothman/gists{/gist_id}","starred_url":"https://api.github.com/users/jnothman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jnothman/subscriptions","organizations_url":"https://api.github.com/users/jnothman/orgs","repos_url":"https://api.github.com/users/jnothman/repos","events_url":"https://api.github.com/users/jnothman/events{/privacy}","received_events_url":"https://api.github.com/users/jnothman/received_events","type":"User","site_admin":false},"created_at":"2015-09-08T03:54:57Z","updated_at":"2015-09-08T03:54:57Z","body":"Neat idea! It's a bit roundabout, given that [a builtin patch is pretty simple](https://github.com/jnothman/jq/tree/byteslength), but I appreciate that minimal changes to builtins, or even the packaged library, are preferred.\r\n\r\nShould we assume instead that this is one for the cookbook and close this issue, or need we evaluate the efficiency of this approach?"}}