Stojanovic had her moments, especially in the first set, before being inevitably overpowered by the No 10 seed in 69 minutes.
The 24-year-old Serb had claimed her maiden win at a major two days earlier against Romanian Irina-Camelia Begu.
"She pushed me really hard and played really well honestly throughout the whole match," said the 39-year-old Williams.
"I had to really fight for all the games.
"It's always good to see young players like her come out and do so well - it's exciting for women's tennis."
Four years after beating older sister Venus in the 2017 final at Melbourne Park for her 23rd grand slam singles title, Williams remains one short of Margaret Court's Open era record of 24.
Williams' third-round opponent will be Russian teen Anastasia Potapova, who ousted Hungarian qualifier Timea Babos 6-2 6-4 earlier on Wednesday.
Williams and Potapova also met in the opening round last year at Melbourne Park, with the American emerging victorious 6-0 6-3.
Meanwhile, two top-10 women's players were bundled out in the second round on Wednesday.
Shortly after eighth-seeded Bianca Andreescu lost to Hsieh Su-wei 6-3, 6-2, ninth-seeded Petra Kvitova was beaten by Romania’s Sorana Cirstea 6-4, 1-6, 6-1.
Kvitova is a two-time Wimbledon champion who reached the 2019 Australian Open final, losing to Naomi Osaka. She had also reached the fourth round or better at five of the past six Grand Slam tournaments.
But Kvitova had 44 unforced errors against Cirstea to just 21 winners.
Andreescu looked out of sorts from the start against Hsieh, who threw the 2019 U.S. Open champion off her rhythm with her deep, angled groundstrokes and array of slices.
Andreescu hadn't played a match for 15 months because of injuries and the Covid-19 pandemic before she beat Mihaela Buzarnescu in the first round at Melbourne Park.