json_pro 1.0.0 copy "json_pro: ^1.0.0" to clipboard
json_pro: ^1.0.0 copied to clipboard

discontinuedreplaced by: json_response

A most easily usable JSON wrapper library in Dart. With JsonPro, you can easily and safely handle JSON on your application.

A most easily usable JSON wrapper library in Dart!

pub package codecov Analyzer Test

1. About #

JsonPro is an open-sourced Dart library.
With JsonPro, you can easily and safely handle JSON on your application.

This library was created with the goal of making JSON easier, more intuitive, and safer to use in the Dart language. For example, as a result of the communication process with the Web API, JSON is returned from the http package and you have ever written the following process when the JSON is set to Response, right?

final json = jsonDecode(value);
final something = json['key'] ?? '';

With JsonPro, the above implementation is no longer necessary!

1.1. Introduction #

1.1.1. Install Library #

With Dart:

 dart pub add json_pro

With Flutter:

 flutter pub add json_pro

1.1.2. Import It #

import 'package:json_pro/json_pro.dart';

1.1.3. Use JsonPro #

import 'dart:typed_data';
import 'package:json_pro/json_pro.dart';

void main() {
  // It provides constructors to get JSON from JSON string, JSON map, and JSON bytes.
  final jsonFromString = Json.fromString(value: '{"test": "something"}');
  final jsonFromMap = Json.fromMap(value: {'test': 'something'});
  final jsonFromBytes = Json.fromBytes(
      bytes: Uint8List.fromList('{"test": "something"}'.codeUnits));

  // You can use handful methods in the same interface once instance is created.
  print(jsonFromString.getString(key: 'test'));
  print(jsonFromMap.getString(key: 'test'));
  print(jsonFromBytes.getString(key: 'test'));

  final testJson = Json.fromMap(
    value: {
      'testValueList': ['value1', 'value2'],
      'testJsonString': '{"key1": "value2"}',
      'testJsonList': [
        {
          'key1': 'value1',
          'key2': 'value2',
        }
      ],
      'testRecursiveJsonList': [
        [
          {
            'key1': 'value1',
            'key2': 'value2',
          }
        ],
        {
          'key3': 'value3',
          'key4': 'value4',
        }
      ]
    },
  );

  if (testJson.isEmpty) {
    // Do something when json is empty.
    return;
  }

  // It provides features to safely get values from JSON.
  print(testJson.getStringValues(key: 'testValueList'));

  // You can easily get a JSON object or JSON list associated with a key.
  // If the JSON object associated with the key is a string,
  // it will be automatically detected and parsed into a JSON object.
  print(testJson.getJson(key: 'testJsonString'));
  print(testJson.getJsonList(key: 'testJsonList'));

  // If your JSON list is nested, that's okay!
  // All JSON expressions associated with a key will be returned as JSON objects.
  print(testJson.getJsonList(key: 'testRecursiveJsonList'));
}

1.2. License #

Copyright (c) 2021, Kato Shinya. All rights reserved.
Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.

1.3. More Information #

JsonPro was designed and implemented by Kato Shinya.

1
likes
130
pub points
12%
popularity

Publisher

unverified uploader

A most easily usable JSON wrapper library in Dart. With JsonPro, you can easily and safely handle JSON on your application.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

More

Packages that depend on json_pro