Walmart Inc. lost out in China by betting on the wrong horse. In India, the retailer is prepared to pay up to secure the top steed. The world\u2019s biggest retailer is nearing a deal to buy a majority stake in India\u2019s top online retailer for at least $12 billion, people familiar with the matter said.\u00a0Flipkart Online Services Pvt\u2019s major investors, including SoftBank Group Corp., are on board with Walmart purchasing as much as 80 percent of the company, the people said, and they may complete the agreement in the coming weeks. In buying Flipkart, Walmart would seek to redress missteps in China, where it initially bought an unprofitable, second-tier online marketplace, then exchanged it five years later for a stake in JD.com, the number-two player behind market leader Alibaba Group Holding Ltd. The strategic shift forced Walmart to play catch-up in the world\u2019s biggest e-commerce market, and Chief Executive Officer Doug McMillon doesn\u2019t want to miss the opportunity before him in the world\u2019s second most-populous nation. \u201cThey missed the boat in China, and they don\u2019t want to make the same mistake in India,\u201d Robert Gregory, global research director at consultant Planet Retail RNG, said by phone. \u201cIt\u2019s quite clear that the future of markets like China and India are online. If Walmart wants to play in India, it has to invest.\u201d Online Competition A Flipkart investment would likely be Walmart\u2019s biggest deal in almost two decades and strike a blow against rival Amazon.com Inc., which holds 27 percent of India\u2019s $30 billion e-commerce market, according to data tracker Euromonitor. Amazon\u2019s market share trails Flipkart\u2019s 34 percent. The online retailer has committed $5.5 billion to expand its business in India, where it\u2019s built a new mobile app and is pushing into new areas like groceries just as it has in the U.S. Walmart has tapped India and China as its two main growth markets abroad. The retailer needs to grab more customers in both nations, since other international regions such as Brazil and the U.K. have floundered. Online sales are the key in those sprawling Asian markets due to the difficulty involved in reaching shoppers with traditional big-box stores. The retailer operates 443 stores in China and 20 member-based wholesale clubs in India. China Deals Walmart\u2019s initial Chinese foray involved buying a stake in online retailer Yihaodian in 2011, hoping to tap into the booming web market and complement its physical locations. But Yihaodian held just 2 percent of Chinese online sales and couldn\u2019t help Walmart gain ground on Alibaba. A series of management reshuffles didn\u2019t help, and so when McMillon became Walmart\u2019s CEO in 2014, fixing China was on the top of his to-do list. In the summer of 2016 McMillon acquired a 5 percent stake in JD.com, which took ownership of Yihaodian as part of the deal, giving Walmart a fresh start in China through access to JD\u2019s flagship online store. Later that year Walmart struck a partnership with a firm called New Dada that provides delivery of online orders in less than an hour. Walmart now owns 12 percent of JD.com, which sells everything from washing machines to ultra-high pasteurized infant milk from Britain through a supply chain that\u2019s linked to Walmart\u2019s. Despite its progress in China, Walmart\u2019s resigned to playing second fiddle there to Alibaba. In India, it has a chance to flip the narrative and be No. 1. \u201cThere will be a big battle to see who will control the Indian online space,\u201d Gregory said.