{"action":"created","comment":{"url":"https://api.github.com/repos/CloudSlang/score-actions/pulls/comments/52900398","id":52900398,"diff_hunk":"@@ -0,0 +1,154 @@\n+package io.cloudslang.content.json.services;\n+\n+import com.jayway.jsonpath.Configuration;\n+import com.jayway.jsonpath.DocumentContext;\n+import com.jayway.jsonpath.JsonPath;\n+import com.jayway.jsonpath.internal.spi.json.GsonJsonProvider;\n+import com.jayway.jsonpath.spi.json.JsonProvider;\n+import io.cloudslang.content.json.exceptions.RemoveEmptyElementException;\n+import net.minidev.json.JSONArray;\n+import net.minidev.json.JSONObject;\n+import net.minidev.json.JSONStyle;\n+\n+import java.util.LinkedHashMap;\n+import java.util.Map;\n+\n+/**\n+ * Created by Folea Ilie Cristian on 2/3/2016.\n+ */\n+public class JsonService {\n+\n+    public String removeEmptyElementsJson(String json) throws RemoveEmptyElementException {\n+        String normalizedJson = removeBlanks(json);\n+\n+        char wrappingQuote = retrieveWrappingQuoteTypeOfJsonMemberNames(normalizedJson);\n+\n+        Map<String, Object> jsonMap;\n+\n+        try {\n+\n+            parseJsonForInconsistencies(normalizedJson);\n+            jsonMap = JsonPath.read(normalizedJson, \"$\");\n+        } catch (com.jayway.jsonpath.InvalidJsonException | com.google.gson.JsonSyntaxException ije) {\n+            throw new RemoveEmptyElementException(ije);\n+        }\n+\n+        removeEmptyElementsFromMap(jsonMap);\n+        return generateResultingJsonString(wrappingQuote, jsonMap);\n+    }\n+\n+    private String generateResultingJsonString(char wrappingQuote, Map<String, Object> jsonMap) {\n+        JSONObject jsonObject = new JSONObject();\n+\n+        for(String key:jsonMap.keySet()){\n+             jsonObject.put(key,jsonMap.get(key));\n+        }\n+\n+        String newJson = jsonObject.toJSONString(JSONStyle.LT_COMPRESS);\n+\n+        if (newJson.charAt(1) != wrappingQuote) {\n+            return replaceUnescapedOccurrencesOfCharacterInText(newJson, newJson.charAt(1), wrappingQuote);\n+        }\n+\n+        return newJson;\n+    }\n+\n+\n+    private void parseJsonForInconsistencies(String normalizedJson) {\n+        JsonProvider provider = new GsonJsonProvider();\n+        Configuration configuration =  Configuration.builder().jsonProvider(provider).build();\n+        JsonPath.parse(normalizedJson, configuration);       //throws an exception at runtime if the json is malformed\n+    }\n+\n+    /**\n+     * Returns the quote character used for specifying json member names and String values of json members\n+     * @param jsonString the source json from which to extract the wrapping quote\n+     * @return either one of the characters ' (single quote)or \" (double quote)\n+     */\n+    private char retrieveWrappingQuoteTypeOfJsonMemberNames(String jsonString) {\n+        char quote = '\\\"';   //  the default quote character used to specify json member names and string value according to the json specification\n+        for (char c : jsonString.toCharArray()) {\n+            if (c == '\\'' || c == '\\\"') {\n+                quote = c;\n+                break;\n+            }\n+        }\n+        return quote;\n+    }\n+\n+    private void removeEmptyElementsFromMap(Map<String, Object> json) {\n+        LinkedHashMap<String, Object> copyJson = new LinkedHashMap<String, Object>(json);\n+        for (Object element : copyJson.values()) {","path":"score-data-format/src/main/java/io/cloudslang/content/json/services/JsonService.java","position":81,"original_position":81,"commit_id":"d27cef4396eb2356e6fa00e24a4bd9a7421432a1","original_commit_id":"d27cef4396eb2356e6fa00e24a4bd9a7421432a1","user":{"login":"gituser173","id":12094982,"avatar_url":"https://avatars.githubusercontent.com/u/12094982?v=3","gravatar_id":"","url":"https://api.github.com/users/gituser173","html_url":"https://github.com/gituser173","followers_url":"https://api.github.com/users/gituser173/followers","following_url":"https://api.github.com/users/gituser173/following{/other_user}","gists_url":"https://api.github.com/users/gituser173/gists{/gist_id}","starred_url":"https://api.github.com/users/gituser173/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gituser173/subscriptions","organizations_url":"https://api.github.com/users/gituser173/orgs","repos_url":"https://api.github.com/users/gituser173/repos","events_url":"https://api.github.com/users/gituser173/events{/privacy}","received_events_url":"https://api.github.com/users/gituser173/received_events","type":"User","site_admin":false},"body":"maybe you could use an iterator over the entrySet here to iterate and remove elements without needing a copy of the map","created_at":"2016-02-15T13:52:58Z","updated_at":"2016-02-15T13:52:58Z","html_url":"https://github.com/CloudSlang/score-actions/pull/91#discussion_r52900398","pull_request_url":"https://api.github.com/repos/CloudSlang/score-actions/pulls/91","_links":{"self":{"href":"https://api.github.com/repos/CloudSlang/score-actions/pulls/comments/52900398"},"html":{"href":"https://github.com/CloudSlang/score-actions/pull/91#discussion_r52900398"},"pull_request":{"href":"https://api.github.com/repos/CloudSlang/score-actions/pulls/91"}}},"pull_request":{"url":"https://api.github.com/repos/CloudSlang/score-actions/pulls/91","id":59194599,"html_url":"https://github.com/CloudSlang/score-actions/pull/91","diff_url":"https://github.com/CloudSlang/score-actions/pull/91.diff","patch_url":"https://github.com/CloudSlang/score-actions/pull/91.patch","issue_url":"https://api.github.com/repos/CloudSlang/score-actions/issues/91","number":91,"state":"open","locked":false,"title":"Added new action for removing empty elements from JSON","user":{"login":"nanebogdan","id":4885554,"avatar_url":"https://avatars.githubusercontent.com/u/4885554?v=3","gravatar_id":"","url":"https://api.github.com/users/nanebogdan","html_url":"https://github.com/nanebogdan","followers_url":"https://api.github.com/users/nanebogdan/followers","following_url":"https://api.github.com/users/nanebogdan/following{/other_user}","gists_url":"https://api.github.com/users/nanebogdan/gists{/gist_id}","starred_url":"https://api.github.com/users/nanebogdan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nanebogdan/subscriptions","organizations_url":"https://api.github.com/users/nanebogdan/orgs","repos_url":"https://api.github.com/users/nanebogdan/repos","events_url":"https://api.github.com/users/nanebogdan/events{/privacy}","received_events_url":"https://api.github.com/users/nanebogdan/received_events","type":"User","site_admin":false},"body":"Provided enhancement on the \"Remove empty elements from Json\" action (included initially in the pull request from https://github.com/Folea/score-actions.git )according to feedback.\r\n\r\n\r\nSigned-off-by: Bogdan Nane <bogdan.nane@hpe.com>\r\n","created_at":"2016-02-12T16:18:58Z","updated_at":"2016-02-15T13:52:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1f225cfee019701bb18756b1ee8b6f4c3544d0ab","assignee":{"login":"gituser173","id":12094982,"avatar_url":"https://avatars.githubusercontent.com/u/12094982?v=3","gravatar_id":"","url":"https://api.github.com/users/gituser173","html_url":"https://github.com/gituser173","followers_url":"https://api.github.com/users/gituser173/followers","following_url":"https://api.github.com/users/gituser173/following{/other_user}","gists_url":"https://api.github.com/users/gituser173/gists{/gist_id}","starred_url":"https://api.github.com/users/gituser173/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gituser173/subscriptions","organizations_url":"https://api.github.com/users/gituser173/orgs","repos_url":"https://api.github.com/users/gituser173/repos","events_url":"https://api.github.com/users/gituser173/events{/privacy}","received_events_url":"https://api.github.com/users/gituser173/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/CloudSlang/score-actions/pulls/91/commits","review_comments_url":"https://api.github.com/repos/CloudSlang/score-actions/pulls/91/comments","review_comment_url":"https://api.github.com/repos/CloudSlang/score-actions/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CloudSlang/score-actions/issues/91/comments","statuses_url":"https://api.github.com/repos/CloudSlang/score-actions/statuses/d27cef4396eb2356e6fa00e24a4bd9a7421432a1","head":{"label":"nanebogdan:master","ref":"master","sha":"d27cef4396eb2356e6fa00e24a4bd9a7421432a1","user":{"login":"nanebogdan","id":4885554,"avatar_url":"https://avatars.githubusercontent.com/u/4885554?v=3","gravatar_id":"","url":"https://api.github.com/users/nanebogdan","html_url":"https://github.com/nanebogdan","followers_url":"https://api.github.com/users/nanebogdan/followers","following_url":"https://api.github.com/users/nanebogdan/following{/other_user}","gists_url":"https://api.github.com/users/nanebogdan/gists{/gist_id}","starred_url":"https://api.github.com/users/nanebogdan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nanebogdan/subscriptions","organizations_url":"https://api.github.com/users/nanebogdan/orgs","repos_url":"https://api.github.com/users/nanebogdan/repos","events_url":"https://api.github.com/users/nanebogdan/events{/privacy}","received_events_url":"https://api.github.com/users/nanebogdan/received_events","type":"User","site_admin":false},"repo":{"id":29724036,"name":"score-actions","full_name":"nanebogdan/score-actions","owner":{"login":"nanebogdan","id":4885554,"avatar_url":"https://avatars.githubusercontent.com/u/4885554?v=3","gravatar_id":"","url":"https://api.github.com/users/nanebogdan","html_url":"https://github.com/nanebogdan","followers_url":"https://api.github.com/users/nanebogdan/followers","following_url":"https://api.github.com/users/nanebogdan/following{/other_user}","gists_url":"https://api.github.com/users/nanebogdan/gists{/gist_id}","starred_url":"https://api.github.com/users/nanebogdan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nanebogdan/subscriptions","organizations_url":"https://api.github.com/users/nanebogdan/orgs","repos_url":"https://api.github.com/users/nanebogdan/repos","events_url":"https://api.github.com/users/nanebogdan/events{/privacy}","received_events_url":"https://api.github.com/users/nanebogdan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nanebogdan/score-actions","description":"Slang content java actions","fork":true,"url":"https://api.github.com/repos/nanebogdan/score-actions","forks_url":"https://api.github.com/repos/nanebogdan/score-actions/forks","keys_url":"https://api.github.com/repos/nanebogdan/score-actions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nanebogdan/score-actions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nanebogdan/score-actions/teams","hooks_url":"https://api.github.com/repos/nanebogdan/score-actions/hooks","issue_events_url":"https://api.github.com/repos/nanebogdan/score-actions/issues/events{/number}","events_url":"https://api.github.com/repos/nanebogdan/score-actions/events","assignees_url":"https://api.github.com/repos/nanebogdan/score-actions/assignees{/user}","branches_url":"https://api.github.com/repos/nanebogdan/score-actions/branches{/branch}","tags_url":"https://api.github.com/repos/nanebogdan/score-actions/tags","blobs_url":"https://api.github.com/repos/nanebogdan/score-actions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nanebogdan/score-actions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nanebogdan/score-actions/git/refs{/sha}","trees_url":"https://api.github.com/repos/nanebogdan/score-actions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nanebogdan/score-actions/statuses/{sha}","languages_url":"https://api.github.com/repos/nanebogdan/score-actions/languages","stargazers_url":"https://api.github.com/repos/nanebogdan/score-actions/stargazers","contributors_url":"https://api.github.com/repos/nanebogdan/score-actions/contributors","subscribers_url":"https://api.github.com/repos/nanebogdan/score-actions/subscribers","subscription_url":"https://api.github.com/repos/nanebogdan/score-actions/subscription","commits_url":"https://api.github.com/repos/nanebogdan/score-actions/commits{/sha}","git_commits_url":"https://api.github.com/repos/nanebogdan/score-actions/git/commits{/sha}","comments_url":"https://api.github.com/repos/nanebogdan/score-actions/comments{/number}","issue_comment_url":"https://api.github.com/repos/nanebogdan/score-actions/issues/comments{/number}","contents_url":"https://api.github.com/repos/nanebogdan/score-actions/contents/{+path}","compare_url":"https://api.github.com/repos/nanebogdan/score-actions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nanebogdan/score-actions/merges","archive_url":"https://api.github.com/repos/nanebogdan/score-actions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nanebogdan/score-actions/downloads","issues_url":"https://api.github.com/repos/nanebogdan/score-actions/issues{/number}","pulls_url":"https://api.github.com/repos/nanebogdan/score-actions/pulls{/number}","milestones_url":"https://api.github.com/repos/nanebogdan/score-actions/milestones{/number}","notifications_url":"https://api.github.com/repos/nanebogdan/score-actions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nanebogdan/score-actions/labels{/name}","releases_url":"https://api.github.com/repos/nanebogdan/score-actions/releases{/id}","deployments_url":"https://api.github.com/repos/nanebogdan/score-actions/deployments","created_at":"2015-01-23T08:39:29Z","updated_at":"2016-02-08T19:32:41Z","pushed_at":"2016-02-14T19:46:00Z","git_url":"git://github.com/nanebogdan/score-actions.git","ssh_url":"git@github.com:nanebogdan/score-actions.git","clone_url":"https://github.com/nanebogdan/score-actions.git","svn_url":"https://github.com/nanebogdan/score-actions","homepage":"","size":1506,"stargazers_count":0,"watchers_count":0,"language":"Java","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":0,"default_branch":"master"}},"base":{"label":"CloudSlang:master","ref":"master","sha":"688d47b0217ecef2fb6f7c13cb044177b7b4d4ac","user":{"login":"CloudSlang","id":10261505,"avatar_url":"https://avatars.githubusercontent.com/u/10261505?v=3","gravatar_id":"","url":"https://api.github.com/users/CloudSlang","html_url":"https://github.com/CloudSlang","followers_url":"https://api.github.com/users/CloudSlang/followers","following_url":"https://api.github.com/users/CloudSlang/following{/other_user}","gists_url":"https://api.github.com/users/CloudSlang/gists{/gist_id}","starred_url":"https://api.github.com/users/CloudSlang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CloudSlang/subscriptions","organizations_url":"https://api.github.com/users/CloudSlang/orgs","repos_url":"https://api.github.com/users/CloudSlang/repos","events_url":"https://api.github.com/users/CloudSlang/events{/privacy}","received_events_url":"https://api.github.com/users/CloudSlang/received_events","type":"Organization","site_admin":false},"repo":{"id":28305374,"name":"score-actions","full_name":"CloudSlang/score-actions","owner":{"login":"CloudSlang","id":10261505,"avatar_url":"https://avatars.githubusercontent.com/u/10261505?v=3","gravatar_id":"","url":"https://api.github.com/users/CloudSlang","html_url":"https://github.com/CloudSlang","followers_url":"https://api.github.com/users/CloudSlang/followers","following_url":"https://api.github.com/users/CloudSlang/following{/other_user}","gists_url":"https://api.github.com/users/CloudSlang/gists{/gist_id}","starred_url":"https://api.github.com/users/CloudSlang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CloudSlang/subscriptions","organizations_url":"https://api.github.com/users/CloudSlang/orgs","repos_url":"https://api.github.com/users/CloudSlang/repos","events_url":"https://api.github.com/users/CloudSlang/events{/privacy}","received_events_url":"https://api.github.com/users/CloudSlang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CloudSlang/score-actions","description":"CloudSlang Content Java Actions","fork":false,"url":"https://api.github.com/repos/CloudSlang/score-actions","forks_url":"https://api.github.com/repos/CloudSlang/score-actions/forks","keys_url":"https://api.github.com/repos/CloudSlang/score-actions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CloudSlang/score-actions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CloudSlang/score-actions/teams","hooks_url":"https://api.github.com/repos/CloudSlang/score-actions/hooks","issue_events_url":"https://api.github.com/repos/CloudSlang/score-actions/issues/events{/number}","events_url":"https://api.github.com/repos/CloudSlang/score-actions/events","assignees_url":"https://api.github.com/repos/CloudSlang/score-actions/assignees{/user}","branches_url":"https://api.github.com/repos/CloudSlang/score-actions/branches{/branch}","tags_url":"https://api.github.com/repos/CloudSlang/score-actions/tags","blobs_url":"https://api.github.com/repos/CloudSlang/score-actions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CloudSlang/score-actions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CloudSlang/score-actions/git/refs{/sha}","trees_url":"https://api.github.com/repos/CloudSlang/score-actions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CloudSlang/score-actions/statuses/{sha}","languages_url":"https://api.github.com/repos/CloudSlang/score-actions/languages","stargazers_url":"https://api.github.com/repos/CloudSlang/score-actions/stargazers","contributors_url":"https://api.github.com/repos/CloudSlang/score-actions/contributors","subscribers_url":"https://api.github.com/repos/CloudSlang/score-actions/subscribers","subscription_url":"https://api.github.com/repos/CloudSlang/score-actions/subscription","commits_url":"https://api.github.com/repos/CloudSlang/score-actions/commits{/sha}","git_commits_url":"https://api.github.com/repos/CloudSlang/score-actions/git/commits{/sha}","comments_url":"https://api.github.com/repos/CloudSlang/score-actions/comments{/number}","issue_comment_url":"https://api.github.com/repos/CloudSlang/score-actions/issues/comments{/number}","contents_url":"https://api.github.com/repos/CloudSlang/score-actions/contents/{+path}","compare_url":"https://api.github.com/repos/CloudSlang/score-actions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CloudSlang/score-actions/merges","archive_url":"https://api.github.com/repos/CloudSlang/score-actions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CloudSlang/score-actions/downloads","issues_url":"https://api.github.com/repos/CloudSlang/score-actions/issues{/number}","pulls_url":"https://api.github.com/repos/CloudSlang/score-actions/pulls{/number}","milestones_url":"https://api.github.com/repos/CloudSlang/score-actions/milestones{/number}","notifications_url":"https://api.github.com/repos/CloudSlang/score-actions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CloudSlang/score-actions/labels{/name}","releases_url":"https://api.github.com/repos/CloudSlang/score-actions/releases{/id}","deployments_url":"https://api.github.com/repos/CloudSlang/score-actions/deployments","created_at":"2014-12-21T16:30:37Z","updated_at":"2016-02-13T07:51:45Z","pushed_at":"2016-02-14T19:46:00Z","git_url":"git://github.com/CloudSlang/score-actions.git","ssh_url":"git@github.com:CloudSlang/score-actions.git","clone_url":"https://github.com/CloudSlang/score-actions.git","svn_url":"https://github.com/CloudSlang/score-actions","homepage":"","size":1863,"stargazers_count":22,"watchers_count":22,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"open_issues_count":4,"forks":17,"open_issues":4,"watchers":22,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CloudSlang/score-actions/pulls/91"},"html":{"href":"https://github.com/CloudSlang/score-actions/pull/91"},"issue":{"href":"https://api.github.com/repos/CloudSlang/score-actions/issues/91"},"comments":{"href":"https://api.github.com/repos/CloudSlang/score-actions/issues/91/comments"},"review_comments":{"href":"https://api.github.com/repos/CloudSlang/score-actions/pulls/91/comments"},"review_comment":{"href":"https://api.github.com/repos/CloudSlang/score-actions/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CloudSlang/score-actions/pulls/91/commits"},"statuses":{"href":"https://api.github.com/repos/CloudSlang/score-actions/statuses/d27cef4396eb2356e6fa00e24a4bd9a7421432a1"}}}}