If the flight number stays the same, you only get the "non-stop" mileage JFK-NRT, which, as you indicated, is quite a bit less than with a break at SFO.
You can avoid this by: (1) flying out of EWR to SFO, or (2) working the connection so that your JFK-SFO and SFO-NRT flight numbers are different.