nice_json 1.1.1 copy "nice_json: ^1.1.1" to clipboard
nice_json: ^1.1.1 copied to clipboard

A nice way to encode nice maps into nice-looking, human-readable json.

example/example.dart

import 'package:nice_json/nice_json.dart';

enum CatColour {
  black,
  white,
  orange,
  grey;
}

void main(List<String> args) {
  Map<String, dynamic> data = {
    'a': [0, 1],
    'b': [
      [0, 1],
      [2, 3],
    ],
    'bools': [true, false],
    'person': {'first_name': 'Alexander', 'last_name': 'Baker'},
    'cats': ['gau', 'saturn', 'yipyip', 'morgana'],
    'catscatscatscatscatscatscatscatscatscatscatscats': [
      'gau',
      'saturn',
      'yipyip',
      'morgana'
    ],
    'kittens': ['boy', 'violet', 'pumpkin'],
    'mixedList': [
      'boy',
      ['violet', 'pumpkin'],
      [1111111, 2222222, 3333333, 4444444, 5555555],
      {'name': 'saturn', 'age': 3, 'species': 'cat', 'colour': CatColour.white},
    ],
    'locations': {
      'loc1': {'x': 0, 'y': -1.5},
      'loc2': {'x': -6.1, 'y': 2},
    },
    'book': 'a really really really really really long'
        ' string will obviously not get wrapped at all',
    'people': [
      {
        'name': 'Alice',
        'numbers': [1, 2, 3],
        'friends': ['Bob', 'Charlie'],
      },
      {
        'name': 'Bob',
        'numbers': [4, 5, 6],
        'friends': ['Alice', 'Charlie'],
      },
    ],
  };

  String json = niceJson(data,
      alwaysExpandKeys: ['kittens', 'locations.loc2', 'people.*.friends']);
  print(json);
}
3
likes
160
pub points
46%
popularity

Publisher

verified publisheralxbkr.xyz

A nice way to encode nice maps into nice-looking, human-readable json.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on nice_json