The U.S. economy has contracted for two straight quarters, but that doesn't mean the country is in a recession. The National Bureau of Economic Research declares when there's a recession, and it hasn't made that declaration thus far. With employment levels still high and other indicators showing the economy is doing well, the data isn't all pointing in one direction.

But instead of getting hung up on whether the country's in a recession or not, investors can just buy some safe stocks that are likely to get through any downturn and pay dividends. Two stocks which fit those criteria and that Warren Buffett's Berkshire Hathaway owns are Johnson & Johnson (JNJ -1.15%) and Kraft Heinz (KHC -0.52%).

1. Johnson & Johnson

Johnson & Johnson is one of Berkshire's smallest holdings, but it's still a stock that can be a safe place to put your money.

The biggest reason for not investing in the company pertains to its legal issues. It is facing nearly 40,000 lawsuits related to its talc-based baby powder products. However, Johnson & Johnson is spinning off that area of its business (consumer health) into a separate entity next year, which will make the remaining company less risky overall.

The bulk of Johnson & Johnson's sales come from other areas of its business anyway. Pharmaceuticals generated $13.3 billion in revenue for the period ended July 3 and made up more than half (55%) of revenue, followed by medtech at $6.9 billion (29%) and then consumer health at $3.8 billion (16%).

Pharmaceutical products are essential for patients, and Johnson & Johnson's medtech business is tied to contracts it has in place with hospitals. Those business units should make the stock a fairly stable investment, regardless of what happens with the economy, and they could help it lead a market recovery. Overall, Johnson & Johnson's financials have been steady over the past decade, and that trend isn't likely to change anytime soon.

JNJ Revenue (Annual) Chart

JNJ revenue (annual). Data by YCharts.

An added incentive to buy and hold the stock is that Johnson & Johnson also pays an above-average dividend yield of 2.7% (versus the S&P 500, which averages 1.5%). And it is a Dividend King, having raised its payouts annually for nearly 60 straight years. Although its shares are down 2% this year, Johnson & Johnson has proved to be a better buy than the S&P, which has fallen 13% over the same time frame.

2. Kraft Heinz

Kraft is another Berkshire holding, but it's a more prominent one, accounting for more than 3% of its equity portfolio.

What makes the stock a good buy, even amid a recession, is the strength of its brands, which include Kraft foods, Heinz, Jell-O, Kool-Aid, and many other popular names that consumers all over the world stock up on.

And even though the company has been raising prices to offset inflation, consumers have still been buying its products. Net sales of $6.6 billion for the quarter ended June 25 were down only 1% year over year. However, when looking at just organic net sales -- which factor out acquisitions, divestitures, and the impact of foreign currency -- the top line was up over 10% versus the prior-year period.

In addition to its brands providing stability, Kraft also has safety in its top customer, Walmart, which last year accounted for more than one-fifth of its net sales. Kraft has generated an operating profit in each of the past four quarters. And during that time it has accumulated $3.2 billion in free cash flow, more than enough to cover the $2 billion in dividend payments it made during that time.

Demand for the company's products is proving to be resilient, and Kraft's strong financials give it a buffer should it face more adversity. At 4.2%, Kraft also offers an even better dividend yield than Johnson & Johnson. And its 7% return this year is also superior to the healthcare stock.