JSON is nothing to do with ServerSide though server side scripting can generate json format variables/strings like PHP does. So json itself is not for server side.
So apparently, and without been able to deal with design patterns at the moment, the way we have to grab some server side variables and put them on script is to, actually, generate all the js script using a server side language.
Ok.
I’ve never used before but, json isn’t something in between the server side and the client side language?
Does anyone know something about it ? Probably is another way for doing it?
As far as I understood from OP’s first post, he is retrieving something from database in an array as he has given a variable ‘fieldOnMyDatabaseObject’ in foreach. So if it is from the database then I think he must use PHP to construct the JS lines in anyway.
Whether you write this code in another file and include that in your main file or you write it on the main file itself but it should be .php file. It is up to you how you want to manage your code.