[
https://issues.apache.org/jira/browse/METRON-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16163005#comment-16163005
]
ASF GitHub Bot commented on METRON-1146:
----------------------------------------
Github user anandsubbu commented on a diff in the pull request:
https://github.com/apache/metron/pull/727#discussion_r138362605
--- Diff:
metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/StringFunctions.java
---
@@ -550,4 +548,90 @@ else if(var.length() == 0) {
return new ParseException("Unable to parse JSON string");
}
}
+
+ @Stellar(name = "JSON_TO_MAP"
+ , description = "Returns a MAP object for the specified JSON
string"
+ , params = {
+ "str - the JSON String to convert, may be null"
+ }
+ , returns = "a MAP object containing the parsed JSON string"
+ )
+ public static class JsonToMap extends BaseStellarFunction {
+
+ @Override
+ public Object apply(List<Object> strings) {
+
+ if (strings == null || strings.size() == 0) {
+ throw new IllegalArgumentException("[JSON_TO_MAP] incorrect
arguments. Usage: JSON_TO_MAP <JSON String>");
+ }
+ String var = (strings.get(0) == null) ? null : (String)
strings.get(0);
+ if (var == null) {
+ return null;
+ } else if (var.length() == 0) {
+ return var;
+ } else {
+ ObjectMapper objectMapper = new ObjectMapper();
+
--- End diff --
Yup, that makes sense @ottobackwards . Cleaned up now.
> Add ability to parse JSON string into JSONObject for stellar
> ------------------------------------------------------------
>
> Key: METRON-1146
> URL: https://issues.apache.org/jira/browse/METRON-1146
> Project: Metron
> Issue Type: Bug
> Reporter: Anand Subramanian
> Assignee: Anand Subramanian
>
> Use jackson to parse a given JSON string and return a JSONObject on the
> stellar. For example:
> {code}
> MAP_GET( 'bar', PARSE_JSON_STRING( '{ "foo" : 1, "bar" : 2}' )
> {code}
> would give the output 2
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)