Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Dart

Idiom #91 Load JSON file into object

Read from the file data.json and write its content into the object x.
Assume the JSON data is suitable for the type of x.

import 'dart:io' show File;
import 'dart:convert' show json;
Map x = json.jsonDecode(await new File('data.json').readAsString());

x is a Map
import 'dart:io' show File;
import 'dart:convert' show json;
Map x = json.jsonDecode(new File('data.json').readAsStringSync());

x is a Map
(require '[clojure.java.io :refer [file]])
(require '[jsonista.core :refer [read-value]])
(def x (read-value (file "data.json")))

New implementation...