While sneakyimp's suggestion should work, in the end an object in JSON is basically an "unordered set of name/value pairs". So, you may find it simpler to just write:
// first, create your object:
$obj = ['var1' => 'first var', 'var2' => 'second var'];
// then you can output the object encoded as json
echo json_encode($obj);