How to encode/decode JSON in FlutterLast updated on October 30, 2020 A Goodman Loading... Loading... Post a comment How to create a Filter/Search ListView in Flutter (2021) October 6, 2021 Flutter: ListTile examples July 29, 2021 Sorting Lists in Dart and Flutter (5 Examples) May 21, 2021 Working with ElevatedButton in Flutter (2021) October 6, 2021 Customize Borders of TextField/TextFormField in Flutter April 1, 2021 How to check Type of a Variable in Flutter November 3, 2020 Flutter: Add a Search Field to an App Bar (2 Approaches) August 10, 2021 Most Popular Packages for State Management in Flutter (2021) October 29, 2021 More This article shows you how to encode/decode JSON in Flutter. 1. Import the dart:convert library:Advertisements import 'dart:convert';2. Use:
ExamplesExample 1: JSON Encoding final products = [ { 'id': 1, 'name': 'Product #1' }, { 'id': 2, 'name': 'Product #2' } ]; print(json.encode(products));Output: [{"id":1,"name":"Product #1"},{"id":2,"name":"Product #2"}]Example 2: JSON decoding final String responseData = '[{"id":1,"name":"Product #1"},{"id":2,"name":"Product #2"}]'; final products = json.decode(responseData); // Print the name of the second product in the list print(products[1]['name']);Output: Product #2Hope this helps Share Tweet Telegram Subscribe Notify of I allow to use my email address and send notification about new comments and replies (you can unsubscribe at any time). Label {} [+] Name* Email* Label {} [+] Name* Email* 0 Comments Inline Feedbacks View all comments Related ArticlesFlutter & Dart: 3 Ways to Generate Random Strings November 24, 2021 Flutter & Dart: Displaying Large Numbers with Digit Grouping November 7, 2021 Flutter: Avoid `print` calls in production code October 29, 2021 Flutter: Create a Password Strength Checker from Scratch October 22, 2021 Flutter: How to Draw a Heart with CustomPaint October 14, 2021 Implementing Tooltips in Flutter October 11, 2021 Flutter: Drawing an N-Pointed Star with CustomClipper October 11, 2021 Adding a Border to Text in Flutter October 4, 2021 Flutter: Stream.periodic example October 4, 2021 Using Static Methods in Dart and Flutter October 1, 2021 Flutter: DropdownButton Example September 22, 2021 Flutter: ExpansionPanelList and ExpansionPanelList.radio examples September 21, 2021 |