Is it possible to parse a JSON string containing a Javascript function into a Jackson JsonNode ?
The (JSON formatted) string I try to parse :
{
"key1" : "value1",
"key2" : "value2",
"key3" : function () {
// some javascript code
}
}
In a Java object, I would expect something like a Map (Javascript function converted to String).
Currently, I have the following exception :
org.codehaus.jackson.JsonParseException: Unrecognized token 'function'
I found lots of features for non-valid JSON use but still not what I would like ...
Any idea ?
Thanks!
JSON doesn't allow functions. It is meant for safe data-transfer though you could encode the function as a string like this:
{
"key1" : "value1",
"key2" : "value2",
"key3" : "function () { ... }"
}
...but upon re-encoding, it would be a string rather than a function unless you were to eval() it (though that could well be unsafe).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With