I understand that the use of eval(json_str) on the client is vulnerable to malicious code. My question is, if json_str was an array constructed by the PHP function json_encode, would I be safe?
For example,
json_str = json_encode(array(record1,
record2,
record3));
would it now be entirely safe to use eval(json_str) inside client-side code?
Yes and no:
Yes: PHP produces valid JSON
No: PHP may as well return malicious code as in JSON.
If you can trust the source, or if you even have full control over it (because its yours), there is no problem.