How can I to load and query local json data in Flutter Mobile App

rootBundle typically is just part of the answer. I would do jsonDecode as well to return an actual json format.

import 'dart:convert';
import 'package:flutter/services.dart';

Future<String> loadAsset() async {
  return jsonDecode(await rootBundle.loadString('assets/config.json'));
}

then on your main, you can now load this to a List<dynamic> for a list formatted json object.

List<dynamic> response;
response = loadAsset();

then from here you can now access your values by,

print(response['currency.01']);

output: United State USD


add your JSON file to the pubspec.yaml

  assets:
    - assets/config.json

and then you can use rootBundle to load it

import 'dart:async' show Future;
import 'package:flutter/services.dart' show rootBundle;

Future<String> loadAsset() async {
  return await rootBundle.loadString('assets/config.json');
}

also take a look at this full example and for querying convert your JSON data into a LIST and then you have a lot of search methods like the where method

Tags:

Json

Load

Flutter