Adapting Marty's answer, since you want this in JSON:
A controller method can return a string with a JSON representation of the data - you can then manipulate it in JavaScript however you want.
OpportunitiesIndex.page
<apex:page controller="OpportunitiesController">
<h3>
Closed Opportunities from JavaScript
</h3>
<ul id="list">
</ul>
<script>
// The controller returns JSON, which is rendered straight
// into the page. No need to make it a string then parse it!
var opportunities = {!opportunities};
// Just as an example, add each opportunity name to the list
var ul = document.getElementById("list");
opportunities.forEach(function(opportunity) {
// Careful - JavaScript is case sensitive!
var li = document.createElement("li");
li.appendChild(document.createTextNode(opportunity.Name));
ul.appendChild(li);
});
</script>
</apex:page>
OpportunitiesController.class
public class OpportunitiesController {
public String getOpportunities() {
return JSON.serialize([
select name,amount,closedate
from Opportunity
where stagename = 'Closed Won'
]);
}
}
References