Japan posted a merchandise trade surplus of 513.510 billion yen in July, the Ministry of Finance said on Thursday.