json_object 1.0.19+1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 46

JsonObject for DART (http://www.dartlang.org)

Version 1.0.19

Usage: Add to pubspec.yaml:

dependencies:

json_object: any

Now M7 (Dart Beta) compatible.

All tests passing with SDK 0.8.10.3_r29803

See Changelog.

You can use JsonObject in two different ways.

1 Accessing JSON Maps in a class-based fashion

Read the article about using this on the dartlang website: http://www.dartlang.org/articles/json-web-service/

JsonObject takes a json string representation, and uses the dart:json library to parse it back into a map. JsonObject then takes the parsed output, and converts any maps (recursively) into JsonObjects, which allow use of dot notation for property access (via noSuchMethod).

Examples:

// create from existing JSON
var person = new JsonObject.fromJsonString('{"name":"Chris"}');
print(person.name);
person.name = "Chris B";
person.namz = "Bob"; //throws an exception, as it wasn't in the original json
                     //good for catching typos
                      
person.isExtendable = true;
person.namz = "Bob" //this is allowed now
String jsonString = JSON.encode(person); // convert back to JSON

It implements Map, so you can convert it back to Json using JSON.encode():

// starting from an empty map
var animal = new JsonObject();  
animal.legs = 4;  // equivalent to animal["legs"] = 4;
animal.name = "Fido"; // equivalent to animal["name"] = "Fido";
String jsonString = JSON.encode(animal); // convert to JSON

Take a look at the unit tests to get an idea of how you can use it.


2. Experimental Using reflection to serialize from a real class instance to JSON

(Requires use of a the experimental mirrors branch)

Use objectToJson(myObj) to return a future containing the serialized string.

Example: import 'package:json_object/json_object.dart';

class Other { String name = "My Name"; }

class Basic {
   String myString = "foo";
   int myInt = 42;
   Other name = new Other();
}

main() {
  var basic = new Basic();
  objectToJson(basic).then((jsonStr) => print(jsonStr));
}

TODO:

  • I still feel that there aren't enough tests - let me know if it works for you.

Many of the unit tests are based around specific questions from users, either here or on stack overflow.

Changelog

1.0.19

  • Added a recursive parameter to constructors to allow for disabling recursive conversion to JsonObjects.

1.0.18+2 07/11/2013

  • Doc fixes.

1.0.18 07/11/2013

  • Changed stringify to encode
  • Removed meta package requirement
  • All tests passing with 0.8.10.3_r29803

1.0.17 17/Sept/2013

  • Added @proxy
  • Migrated from dart:json to dart:convert library
  • All tests passing with 0.7.2.1_r27268

1. Depend on it

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


dependencies:
  json_object: "^1.0.19+1"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:json_object/json_object.dart';
        
Version Uploaded Documentation Archive
1.0.19+1 Feb 2, 2016 Go to the documentation of json_object 1.0.19+1 Download json_object 1.0.19+1 archive
1.0.19 Apr 2, 2015 failed Download json_object 1.0.19 archive
1.0.18+2 Nov 7, 2013 failed Download json_object 1.0.18+2 archive
1.0.18+1 Nov 7, 2013 failed Download json_object 1.0.18+1 archive
1.0.18 Nov 7, 2013 failed Download json_object 1.0.18 archive
1.0.17 Sep 17, 2013 failed Download json_object 1.0.17 archive
1.0.16 Jul 12, 2013 failed Download json_object 1.0.16 archive
1.0.15+3 Jun 26, 2013 failed Download json_object 1.0.15+3 archive
1.0.15+2 May 3, 2013 failed Download json_object 1.0.15+2 archive
1.0.15+1 Apr 26, 2013 failed Download json_object 1.0.15+1 archive

All 22 versions...

Analysis

We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
91 / 100
Health:
Code health derived from static analysis. [more]
2 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0 / 100
Overall score:
Weighted score of the above. [more]
46
Learn more about scoring.

Platforms

Detected platforms: web, other

Primary library: package:json_object/json_object.dart with components: mirrors.

Suggestions

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 15 errors 7 hints.

    Strong-mode analysis of lib/json_object.dart failed with the following error:

    line: 31 col: 7
    Inconsistent declarations of 'cast' are inherited from <RK,RV>() → Map<RK, RV>, <R>() → Iterable<R>.

    Strong-mode analysis of lib/src/mirror_based_serializer.dart failed with the following error:

    line: 127 col: 16
    The getter 'getters' isn't defined for the class 'ClassMirror'.

    Similar analysis of the following files failed:

    • lib/src/mirror_based_deserializer.dart (hint)
  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use json_object.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=0.6.0+1.r24898
Dev dependencies
unittest >=0.6.0+1