Be sure to take a look at the source code:
function fromJson(json) {
return isString(json)
? JSON.parse(json)
: json;
}
It simply passes through to JSON.parse
.
Regarding $eval, it delegates to $parse:
// $scope.$eval source:
$eval: function(expr, locals) {
return $parse(expr)(this, locals);
},
The source of $parse is too lengthy to include here, but it basically has the ability to convert inline (stringified) objects into actual Objects, so it's logical that in this case, it will also convert your JSON.
(I only discovered this upon examining the $parse source just now.)
Is there any specific reason to use angular.fromJSON instead of JSON.parse?
Not really. The primary purpose is to prevent double-parsing of a JSON string, like this:
var jsonString = '{"foo":"bar"}';
var json = JSON.parse(jsonString); // Parsing once is good :)
JSON.parse(json); // Parsing twice is bad :(
Are there any potential issues when using $scope.$eval to parse a JSON string?
I can't think of any off the top of my head, other than the fact that it involves more work than necessary. If you know you're dealing with JSON data, there's no need to use the heavier $parse function.