xson 0.0.8+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 71

A library for Dart developers.

Usage #

A simple usage example:

import 'dart:io';

import 'package:xson/xson.dart' as xson;
import '../example/generated/output.dart';

main() async {
  File from = File('./example/sample2.json');
  File output = File('./example/generated/output.dart');
  await xson.generateJsonBeanFile(from.readAsStringSync(), output, runBuildRunner: true);

  String jsonSource = from.readAsStringSync();
  dynamic json = xson.jsonDecode(jsonSource);
  OutputBean outputBean = OutputBean.fromJson(json);
  String encode = xson.jsonEncode(outputBean.toJson());
  print(encode);
}

Features and bugs #

0.0.1 #

  • Initial version, created by Stagehand

0.0.6+3 #

  • change named rule of nested class name, prefix top-level class name to every nested class

  • update json serialize/deserialize interface of generated bean:

    • factory Bean.fromJson(dynamic json);

    • dynamic toJson();

dynamic must be list(json array) or map(json object), if neither is then an error will be thrown

0.0.6+4 #

  • new rule of named mode, all illegal character will be replaced with "_"

ex:

"an-apple" - "an_apple" - "anApple"

"an..apple****pie" - "an_apple_pie" - "anApplePie"

"100...test" - "$100_test" - "$100Test"

0.0.6+5 #

  • fixed bugs

0.0.7 #

  • type auto transformer of all property

  • now you can specific property type at json source just generate some tag anywhere like this:

{
    "a":100,
    "b":[
        {
            "c": 200
        }
    ]
}
//@.a=String
//@.b[].c=String

0.0.7+5 #

  • fixed bugs of nested List parsed

0.0.8 #

  • fixed transformer of List

0.0.8+1 #

  • bug fixed

example/xson_example.dart

import 'dart:io';

import 'package:xson/xson.dart' as xson;

//import 'generated/output.dart';

main() async {
  File from = File('./example/sample.json');
  File output = File('./example/generated/output.dart');
  await xson.generateJsonBeanFile(from.readAsStringSync(), output, runBuildRunner: false);
//
  String jsonSource = from.readAsStringSync();
  jsonSource = xson.readJsonIgnoreComments(jsonSource);
  dynamic json = xson.jsonDecode(jsonSource);
//  OutputBean outputBean = OutputBean.fromJson(json);
//  String encode = xson.jsonEncode(outputBean.toJson());
//  print(encode);
}

Use this package as a library

1. Depend on it

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


dependencies:
  xson: ^0.0.8+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:xson/xson.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
49
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
82
Overall:
Weighted score of the above. [more]
71
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:xson/xson.dart with components: io.

Health suggestions

Fix lib/src/xson_core.dart. (-0.50 points)

Analysis of lib/src/xson_core.dart reported 1 hint:

line 96 col 8: The declaration '_makeJsonBeanToFile' isn't referenced.

Fix lib/src/xson_runner.dart. (-0.50 points)

Analysis of lib/src/xson_runner.dart reported 1 hint:

line 6 col 13: The value of the local variable 'json' isn't used.

Format lib/src/json_array.dart.

Run dartfmt to format lib/src/json_array.dart.

Fix additional 4 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/json_info.dart (Run dartfmt to format lib/src/json_info.dart.)
  • lib/src/json_object.dart (Run dartfmt to format lib/src/json_object.dart.)
  • lib/src/json_primitive.dart (Run dartfmt to format lib/src/json_primitive.dart.)
  • lib/xson.dart (Run dartfmt to format lib/xson.dart.)

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

The package description is too short. (-8 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
dartpoet ^1.0.3+2 1.0.3+2
named_mode ^1.0.1 1.0.2+1
xfile ^1.0.2 1.0.2
Transitive dependencies
analyzer 0.38.5
args 1.5.2
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.3.1
front_end 0.1.27
glob 1.1.7
html 0.14.0+3
kernel 0.3.27
meta 1.1.7
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
pub_semver 1.4.2
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.2.0
Dev dependencies
build_runner ^1.6.7