yaon 1.1.4+10 copy "yaon: ^1.1.4+10" to clipboard
yaon: ^1.1.4+10 copied to clipboard

A simple library to parse either a string from either yaml or json.

Table of Contents

yaon #

A Dart library that can parse a string encoded as either JSON or YAML into a resulting map or array. As a note, for small data sets JSON and YAML can prossess in similar amounts of time but for large data sets, YAML is significantly more expensive, often at a factor of about 10x. So for configuration, YAML can be a great choice but for large objects, JSON will be more performant.

The use of BSON was investigated as another option. However, multiple tests showed that BSON was slower than JSON, even for Dart native compiled applications, and found a suggestion that it's even slower on web.

BSON support may be added in the future should the performance metrics change but for now, there's no meaningful advantage that BSON provides over JSON or YAML.

Using the library #

Add the repo to your Dart pubspec.yaml file.

dependencies:
  yaon: <<version>> 

Then run...

dart pub get

Example #

import 'package:yaon/yaon.dart';

void main() {
  final inputJson = '''
{
  "foo": "bar",
  "list": [
    1, 2, 3, 5, 8
  ],
  "map": {
    "one": 1,
    "two": 2
  },
  "multiline": "First Line\\nSecond Line\\nThird Line"
}
''';

  final inputYaml = '''
foo: bar
list:
  - 1
  - 2
  - 3
  - 5
  - 8
map:
  one: 1
  two: 2
multiline: |-
  First Line
  Second Line
  Third Line

''';
  var result = yaon.parse(inputJson);
  print(result['map']['one']); // 1

  result = yaon.parse(inputYaml);
  print(result['map']['two']); // 2
}

Normalization of Results #

As a note, there are some technical differences between JSON and YMAL capabilities. While JSON can only have string based keys, YAML allows for other types. If you would like to prevent the possibility of primitive keys, when parsing set normalize: true and it will guarantee all keys in all returned maps are strings.

0
likes
150
pub points
79%
popularity

Publisher

verified publisherpeifferinnovations.com

A simple library to parse either a string from either yaml or json.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

logging, yaml

More

Packages that depend on yaon