json_utilities 0.1.3

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 84

json_utilities #

Dart/Flutter package to enhance the experience of working with json based models.

Can be used in conjunction with json_serializable.

See Examples for more details.

General Idea #

The general/basic idea was to have something similar like lodash or ramda when working with 'JSON' / Map<String,dynamic> in Dart.

Some operations like checking for existence of certain JSON leafs can be tedious, that's where this package is supposed to come in and save the day!

This is a growing library, contributions are welcome!

Usage #

To use this plugin, add json_utilites as a dependency in your pubspec.yaml file

Examples #

Basic Example #

import 'package:json_utilities/json_utilities.dart';

var json = <String, dynamic>{
  'root': 'value',
  'root2': <String, dynamic>{'leaf': 'fruit'}
};

JSONUtils().get(json,'root.leaf', 'defaultValue') // returns String defaultValue
JSONUtils().get(json,'root', 'defaultValue') // returns String value
JSONUtils().get(json,'root2', 'defaultValue') // <String, dynamic>{'leaf': 'fruit'}
JSONUtils().get(json,'root.leaf.deeperLeaf', 'defaultValue') / returns String defaultValue

json_serializable Example #

// model/Condition.dart
import 'package:json_annotation/json_annotation.dart';

part 'Condition.g.dart';

@JsonSerializable()
class Condition {

  String text;
  String language;

  Condition({this.text,this.language});

  /*
   * Json to Location object
   */
  factory Condition.fromJson(Map<String, dynamic> json) =>
      _$ConditionFromJson(json);

  /*
   * Location object to json
   */
  Map<String, dynamic> toJson() => _$ConditionToJson(this);

}
import 'package:json_utilities/json_utilities.dart';
import 'model/Condition.dart';

Foo{
    Condition condition;

    FOO(this.condition);

    getLanguage(){
       return JSONUtils().get(condition.toJson(),'language', 'none');
    }
}

0.1.1

  • Added CHANGELOG.md and README.md with basic examples
  • Added MIT License

0.1.0

  • Initial release

example/main.dart

import 'package:json_utilities/json_utilities.dart';

var json = <String, dynamic>{
  'root': 'value',
  'root2': <String, dynamic>{'leaf': 'fruit'}
};

String value = JSONUtils().get(json,'root.leaf', 'defaultValue');

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  json_utilities: ^0.1.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:json_utilities/json_utilities.dart';
  
Version Uploaded Documentation Archive
0.1.3 Jan 7, 2019 Go to the documentation of json_utilities 0.1.3 Download json_utilities 0.1.3 archive
0.1.2 Dec 27, 2018 Go to the documentation of json_utilities 0.1.2 Download json_utilities 0.1.2 archive
0.1.1 Dec 21, 2018 Go to the documentation of json_utilities 0.1.1 Download json_utilities 0.1.1 archive
0.1.0 Dec 20, 2018 Go to the documentation of json_utilities 0.1.0 Download json_utilities 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
68
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
84
Learn more about scoring.

We analyzed this package on May 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.0
  • pana: 0.12.15
  • Flutter: 1.5.8

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/json_utilities.dart.

Run flutter format to format lib/json_utilities.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test