How to connect to a public node through json RPC? I found a list of public bitcoin nodes here.  I am using a php library. How can I connect to these nodes via JSON RPC? Is it safe to connect to public nodes? What should I give as username and password?

I had tried a bitcoin node on my ec2 instance. It is taking too long to sync and blockchain size is also increasing. I want to communicate with bitcoin network without running a bitcoin daemon.
Not all nodes will have the JSON-RPC enabled, and especially without private credentials. You will probably find a block explorer API much more accessible, because they are built to handle public traffic. There are many blockchain explorers online that have public apis, they are easy to find.