Home > Blockchain >  I've a json object which is not bear a proper characteristic for json key, so how can formatted
I've a json object which is not bear a proper characteristic for json key, so how can formatted

Time:11-16

{ "language": { "blogs details": "blogs details", "Search products": "Search products", "Somethings went wrong": "Somethings went wrong", "Become seller": "Become seller", "Cart": "Cart", "Your name": "Your Name", "Checkout": "Checkout" } }

I'm Expecting like this

{ "language": { "blogs_details": "blogs details", "search_products": "Search products", "Somethings_went_wrong": "Somethings went wrong", "become_seller": "Become seller", "cart": "Cart", "your_name": "Your Name", "checkout": "Checkout" } }

CodePudding user response:

Map data = {
  "blogs details": "blogs details",
  "Somethings went wrong": "Somethings went wrong",
  "Cart": "Cart",
};
Map newMap = {};
data.forEach((key, value) {
  if (key.contains(' ')) {
    var newKey = key.toString().replaceAll(' ', '_').toLowerCase();
    newMap[newKey] = value;
  } else {
    var newKey = key.toString().toLowerCase();
    newMap[newKey] = value;
  }
});
print('newMap: ${newMap}');
  • Related