{"action":"created","comment":{"url":"https://api.github.com/repos/cfengine/core/pulls/comments/58056397","id":58056397,"diff_hunk":"@@ -2699,6 +2699,70 @@ bool EvalContextVariablePutSpecialEscaped(EvalContext *ctx, SpecialScope scope,\n     return EvalContextVariablePutSpecial(ctx, scope, lval, value, type, tags);\n }\n \n+/*********************************************************************/\n+\n+static JsonElement* ExecJSON_Pipe(const char *cmd, JsonElement *container)\n+{\n+    IOData io = cf_popen_full_duplex(cmd, false, false);\n+\n+    if (io.write_fd == -1 || io.read_fd == -1)\n+    {\n+        Log(LOG_LEVEL_INFO, \"An error occurred while communicating with '%s'\", cmd);\n+        return NULL;\n+    }\n+\n+    Log(LOG_LEVEL_DEBUG, \"Opened fds %d and %d for command '%s'.\",\n+        io.read_fd, io.write_fd, cmd);\n+\n+    // write the container to a string\n+    Writer *w = StringWriter();\n+    JsonWrite(w, container, 0);\n+    char *container_str = StringWriterClose(w);\n+\n+    if (PipeWrite(&io, container_str) != strlen(container_str))\n+    {\n+        Log(LOG_LEVEL_VERBOSE, \"Couldn't send whole container data to '%s'.\", cmd);\n+        free(container_str);\n+        return NULL;\n+    }\n+\n+    free(container_str);\n+\n+    /* We can have some error message here. */\n+    Rlist *returnlist = PipeReadData(&io, 5, 5);\n+\n+    /* If script returns non 0 status */\n+    int close = cf_pclose_full_duplex(&io);\n+    if (close != EXIT_SUCCESS)\n+    {\n+        Log(LOG_LEVEL_VERBOSE,\n+            \"%s returned with non zero return code: %d\",\n+            cmd, close);\n+    }\n+\n+    JsonElement *returnjq = JsonArrayCreate(5);\n+\n+    for (const Rlist *rp = returnlist; rp != NULL; rp = rp->next)\n+    {\n+        const char *data = RlistScalarValue(rp);\n+        JsonElement *parsed = NULL;\n+        if (JsonParse(&data, &parsed) == JSON_PARSE_OK)","path":"libpromises/evalfunction.c","position":62,"original_position":51,"commit_id":"d82ce2031b14b3280bbb63feb0eba1d0382fb68b","original_commit_id":"22faa868b27898b8a92e2e585fd183a25d2d27ed","user":{"login":"tzz","id":67764,"avatar_url":"https://avatars.githubusercontent.com/u/67764?v=3","gravatar_id":"","url":"https://api.github.com/users/tzz","html_url":"https://github.com/tzz","followers_url":"https://api.github.com/users/tzz/followers","following_url":"https://api.github.com/users/tzz/following{/other_user}","gists_url":"https://api.github.com/users/tzz/gists{/gist_id}","starred_url":"https://api.github.com/users/tzz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzz/subscriptions","organizations_url":"https://api.github.com/users/tzz/orgs","repos_url":"https://api.github.com/users/tzz/repos","events_url":"https://api.github.com/users/tzz/events{/privacy}","received_events_url":"https://api.github.com/users/tzz/received_events","type":"User","site_admin":false},"body":"You're right, the JSON standard specifies that whitespace includes newlines and carriage returns and we should accept them. I'll add that.","created_at":"2016-03-31T13:52:41Z","updated_at":"2016-03-31T13:52:41Z","html_url":"https://github.com/cfengine/core/pull/2319#discussion_r58056397","pull_request_url":"https://api.github.com/repos/cfengine/core/pulls/2319","_links":{"self":{"href":"https://api.github.com/repos/cfengine/core/pulls/comments/58056397"},"html":{"href":"https://github.com/cfengine/core/pull/2319#discussion_r58056397"},"pull_request":{"href":"https://api.github.com/repos/cfengine/core/pulls/2319"}}},"pull_request":{"url":"https://api.github.com/repos/cfengine/core/pulls/2319","id":45153014,"html_url":"https://github.com/cfengine/core/pull/2319","diff_url":"https://github.com/cfengine/core/pull/2319.diff","patch_url":"https://github.com/cfengine/core/pull/2319.patch","issue_url":"https://api.github.com/repos/cfengine/core/issues/2319","number":2319,"state":"open","locked":false,"title":"jq integration","user":{"login":"tzz","id":67764,"avatar_url":"https://avatars.githubusercontent.com/u/67764?v=3","gravatar_id":"","url":"https://api.github.com/users/tzz","html_url":"https://github.com/tzz","followers_url":"https://api.github.com/users/tzz/followers","following_url":"https://api.github.com/users/tzz/following{/other_user}","gists_url":"https://api.github.com/users/tzz/gists{/gist_id}","starred_url":"https://api.github.com/users/tzz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzz/subscriptions","organizations_url":"https://api.github.com/users/tzz/orgs","repos_url":"https://api.github.com/users/tzz/repos","events_url":"https://api.github.com/users/tzz/events{/privacy}","received_events_url":"https://api.github.com/users/tzz/received_events","type":"User","site_admin":false},"body":"see https://dev.cfengine.com/issues/7435\r\n\r\nHere's a minimal example to test things:\r\n\r\n```\r\nbundle agent main\r\n{\r\n  vars:\r\n      \"items\" data => '{\"user\":\"stedolan\",\"titles\":[\"JQ Primer\", \"More JQ\"]}';\r\n      \"items2\" data => mapdata(\"jq\", \"{user, title: .titles[]}\", items);\r\n      \"items2_str\" string => format(\"%S\", items2);\r\n\r\n  reports:\r\n      \"we have item $(items)\";\r\n      \"we have items2 $(items2_str)\";\r\n}\r\n```\r\n\r\noutput:\r\n\r\n```\r\nR: we have item stedolan\r\nR: we have items2 [{\"title\":\"JQ Primer\",\"user\":\"stedolan\"},{\"title\":\"More JQ\",\"user\":\"stedolan\"}]\r\n```\r\n","created_at":"2015-09-16T10:09:17Z","updated_at":"2016-03-31T13:52:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4ebc96e020a7b8b114da21bfbe3beae3707acdc0","assignee":{"login":"kacf","id":4037094,"avatar_url":"https://avatars.githubusercontent.com/u/4037094?v=3","gravatar_id":"","url":"https://api.github.com/users/kacf","html_url":"https://github.com/kacf","followers_url":"https://api.github.com/users/kacf/followers","following_url":"https://api.github.com/users/kacf/following{/other_user}","gists_url":"https://api.github.com/users/kacf/gists{/gist_id}","starred_url":"https://api.github.com/users/kacf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kacf/subscriptions","organizations_url":"https://api.github.com/users/kacf/orgs","repos_url":"https://api.github.com/users/kacf/repos","events_url":"https://api.github.com/users/kacf/events{/privacy}","received_events_url":"https://api.github.com/users/kacf/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/cfengine/core/pulls/2319/commits","review_comments_url":"https://api.github.com/repos/cfengine/core/pulls/2319/comments","review_comment_url":"https://api.github.com/repos/cfengine/core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cfengine/core/issues/2319/comments","statuses_url":"https://api.github.com/repos/cfengine/core/statuses/d82ce2031b14b3280bbb63feb0eba1d0382fb68b","head":{"label":"tzz:feature/jq","ref":"feature/jq","sha":"d82ce2031b14b3280bbb63feb0eba1d0382fb68b","user":{"login":"tzz","id":67764,"avatar_url":"https://avatars.githubusercontent.com/u/67764?v=3","gravatar_id":"","url":"https://api.github.com/users/tzz","html_url":"https://github.com/tzz","followers_url":"https://api.github.com/users/tzz/followers","following_url":"https://api.github.com/users/tzz/following{/other_user}","gists_url":"https://api.github.com/users/tzz/gists{/gist_id}","starred_url":"https://api.github.com/users/tzz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzz/subscriptions","organizations_url":"https://api.github.com/users/tzz/orgs","repos_url":"https://api.github.com/users/tzz/repos","events_url":"https://api.github.com/users/tzz/events{/privacy}","received_events_url":"https://api.github.com/users/tzz/received_events","type":"User","site_admin":false},"repo":{"id":5155224,"name":"core","full_name":"tzz/core","owner":{"login":"tzz","id":67764,"avatar_url":"https://avatars.githubusercontent.com/u/67764?v=3","gravatar_id":"","url":"https://api.github.com/users/tzz","html_url":"https://github.com/tzz","followers_url":"https://api.github.com/users/tzz/followers","following_url":"https://api.github.com/users/tzz/following{/other_user}","gists_url":"https://api.github.com/users/tzz/gists{/gist_id}","starred_url":"https://api.github.com/users/tzz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzz/subscriptions","organizations_url":"https://api.github.com/users/tzz/orgs","repos_url":"https://api.github.com/users/tzz/repos","events_url":"https://api.github.com/users/tzz/events{/privacy}","received_events_url":"https://api.github.com/users/tzz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tzz/core","description":"CFEngine Community","fork":true,"url":"https://api.github.com/repos/tzz/core","forks_url":"https://api.github.com/repos/tzz/core/forks","keys_url":"https://api.github.com/repos/tzz/core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tzz/core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tzz/core/teams","hooks_url":"https://api.github.com/repos/tzz/core/hooks","issue_events_url":"https://api.github.com/repos/tzz/core/issues/events{/number}","events_url":"https://api.github.com/repos/tzz/core/events","assignees_url":"https://api.github.com/repos/tzz/core/assignees{/user}","branches_url":"https://api.github.com/repos/tzz/core/branches{/branch}","tags_url":"https://api.github.com/repos/tzz/core/tags","blobs_url":"https://api.github.com/repos/tzz/core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tzz/core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tzz/core/git/refs{/sha}","trees_url":"https://api.github.com/repos/tzz/core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tzz/core/statuses/{sha}","languages_url":"https://api.github.com/repos/tzz/core/languages","stargazers_url":"https://api.github.com/repos/tzz/core/stargazers","contributors_url":"https://api.github.com/repos/tzz/core/contributors","subscribers_url":"https://api.github.com/repos/tzz/core/subscribers","subscription_url":"https://api.github.com/repos/tzz/core/subscription","commits_url":"https://api.github.com/repos/tzz/core/commits{/sha}","git_commits_url":"https://api.github.com/repos/tzz/core/git/commits{/sha}","comments_url":"https://api.github.com/repos/tzz/core/comments{/number}","issue_comment_url":"https://api.github.com/repos/tzz/core/issues/comments{/number}","contents_url":"https://api.github.com/repos/tzz/core/contents/{+path}","compare_url":"https://api.github.com/repos/tzz/core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tzz/core/merges","archive_url":"https://api.github.com/repos/tzz/core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tzz/core/downloads","issues_url":"https://api.github.com/repos/tzz/core/issues{/number}","pulls_url":"https://api.github.com/repos/tzz/core/pulls{/number}","milestones_url":"https://api.github.com/repos/tzz/core/milestones{/number}","notifications_url":"https://api.github.com/repos/tzz/core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tzz/core/labels{/name}","releases_url":"https://api.github.com/repos/tzz/core/releases{/id}","deployments_url":"https://api.github.com/repos/tzz/core/deployments","created_at":"2012-07-23T17:54:47Z","updated_at":"2014-06-24T13:51:12Z","pushed_at":"2016-03-31T13:24:05Z","git_url":"git://github.com/tzz/core.git","ssh_url":"git@github.com:tzz/core.git","clone_url":"https://github.com/tzz/core.git","svn_url":"https://github.com/tzz/core","homepage":"https://cfengine.com/community/","size":52663,"stargazers_count":1,"watchers_count":1,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"cfengine:master","ref":"master","sha":"a40deb2d96f5cb36484c24e1331bc9365bdef5fe","user":{"login":"cfengine","id":1239823,"avatar_url":"https://avatars.githubusercontent.com/u/1239823?v=3","gravatar_id":"","url":"https://api.github.com/users/cfengine","html_url":"https://github.com/cfengine","followers_url":"https://api.github.com/users/cfengine/followers","following_url":"https://api.github.com/users/cfengine/following{/other_user}","gists_url":"https://api.github.com/users/cfengine/gists{/gist_id}","starred_url":"https://api.github.com/users/cfengine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cfengine/subscriptions","organizations_url":"https://api.github.com/users/cfengine/orgs","repos_url":"https://api.github.com/users/cfengine/repos","events_url":"https://api.github.com/users/cfengine/events{/privacy}","received_events_url":"https://api.github.com/users/cfengine/received_events","type":"Organization","site_admin":false},"repo":{"id":3543548,"name":"core","full_name":"cfengine/core","owner":{"login":"cfengine","id":1239823,"avatar_url":"https://avatars.githubusercontent.com/u/1239823?v=3","gravatar_id":"","url":"https://api.github.com/users/cfengine","html_url":"https://github.com/cfengine","followers_url":"https://api.github.com/users/cfengine/followers","following_url":"https://api.github.com/users/cfengine/following{/other_user}","gists_url":"https://api.github.com/users/cfengine/gists{/gist_id}","starred_url":"https://api.github.com/users/cfengine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cfengine/subscriptions","organizations_url":"https://api.github.com/users/cfengine/orgs","repos_url":"https://api.github.com/users/cfengine/repos","events_url":"https://api.github.com/users/cfengine/events{/privacy}","received_events_url":"https://api.github.com/users/cfengine/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cfengine/core","description":"CFEngine Community","fork":false,"url":"https://api.github.com/repos/cfengine/core","forks_url":"https://api.github.com/repos/cfengine/core/forks","keys_url":"https://api.github.com/repos/cfengine/core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cfengine/core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cfengine/core/teams","hooks_url":"https://api.github.com/repos/cfengine/core/hooks","issue_events_url":"https://api.github.com/repos/cfengine/core/issues/events{/number}","events_url":"https://api.github.com/repos/cfengine/core/events","assignees_url":"https://api.github.com/repos/cfengine/core/assignees{/user}","branches_url":"https://api.github.com/repos/cfengine/core/branches{/branch}","tags_url":"https://api.github.com/repos/cfengine/core/tags","blobs_url":"https://api.github.com/repos/cfengine/core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cfengine/core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cfengine/core/git/refs{/sha}","trees_url":"https://api.github.com/repos/cfengine/core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cfengine/core/statuses/{sha}","languages_url":"https://api.github.com/repos/cfengine/core/languages","stargazers_url":"https://api.github.com/repos/cfengine/core/stargazers","contributors_url":"https://api.github.com/repos/cfengine/core/contributors","subscribers_url":"https://api.github.com/repos/cfengine/core/subscribers","subscription_url":"https://api.github.com/repos/cfengine/core/subscription","commits_url":"https://api.github.com/repos/cfengine/core/commits{/sha}","git_commits_url":"https://api.github.com/repos/cfengine/core/git/commits{/sha}","comments_url":"https://api.github.com/repos/cfengine/core/comments{/number}","issue_comment_url":"https://api.github.com/repos/cfengine/core/issues/comments{/number}","contents_url":"https://api.github.com/repos/cfengine/core/contents/{+path}","compare_url":"https://api.github.com/repos/cfengine/core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cfengine/core/merges","archive_url":"https://api.github.com/repos/cfengine/core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cfengine/core/downloads","issues_url":"https://api.github.com/repos/cfengine/core/issues{/number}","pulls_url":"https://api.github.com/repos/cfengine/core/pulls{/number}","milestones_url":"https://api.github.com/repos/cfengine/core/milestones{/number}","notifications_url":"https://api.github.com/repos/cfengine/core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cfengine/core/labels{/name}","releases_url":"https://api.github.com/repos/cfengine/core/releases{/id}","deployments_url":"https://api.github.com/repos/cfengine/core/deployments","created_at":"2012-02-25T09:19:05Z","updated_at":"2016-03-12T18:35:11Z","pushed_at":"2016-03-31T13:24:06Z","git_url":"git://github.com/cfengine/core.git","ssh_url":"git@github.com:cfengine/core.git","clone_url":"https://github.com/cfengine/core.git","svn_url":"https://github.com/cfengine/core","homepage":"https://cfengine.com/community/","size":70507,"stargazers_count":235,"watchers_count":235,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":144,"mirror_url":null,"open_issues_count":17,"forks":144,"open_issues":17,"watchers":235,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cfengine/core/pulls/2319"},"html":{"href":"https://github.com/cfengine/core/pull/2319"},"issue":{"href":"https://api.github.com/repos/cfengine/core/issues/2319"},"comments":{"href":"https://api.github.com/repos/cfengine/core/issues/2319/comments"},"review_comments":{"href":"https://api.github.com/repos/cfengine/core/pulls/2319/comments"},"review_comment":{"href":"https://api.github.com/repos/cfengine/core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cfengine/core/pulls/2319/commits"},"statuses":{"href":"https://api.github.com/repos/cfengine/core/statuses/d82ce2031b14b3280bbb63feb0eba1d0382fb68b"}}}}