A most easily usable JSON wrapper library in Dart

Overview

A most easily usable JSON response wrapper library in Dart!

pub package codecov Analyzer Test

1. About

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

This library was created with the goal of making JSON response 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(response.body);
final something = json['key'] ?? '';

With JsonResponse, the above implementation is no longer necessary!

1.1. Introduction

1.1.1. Install Library

With Dart:

 dart pub add json_response

With Flutter:

 flutter pub add json_response

1.1.2. Import It

import 'package:json_response/json_response.dart';

1.1.3. Use JsonResponse

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

void main() {
  // It provides constructors to get JSON from JSON string, JSON map, and JSON bytes.
  final jsonFromString = JsonResponse.fromString(value: '{"test": "something"}');
  final jsonFromMap = JsonResponse.fromMap(value: {'test': 'something'});
  final jsonFromBytes = JsonResponse.fromBytes(
      value: 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 = JsonResponse.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

JsonResponse was designed and implemented by Kato Shinya.

You might also like...

🎯 This library automatically generates object classes from JSON files that can be parsed by the freezed library.

🎯 This library automatically generates object classes from JSON files that can be parsed by the freezed library.

The Most Powerful Way to Automatically Generate Model Objects from JSON Files ⚡ 1. Guide 🌎 1.1. Features 💎 1.1.1. From 1.1.2. To 1.2. Getting Starte

Nov 9, 2022

Most popular and easy to use open source UI library with 1000+ Widgets to build flutter app.

Most popular and easy to use open source UI library with 1000+ Widgets to build flutter app.

GetWidget is a 100% free Flutter open-source UI Kit library built with Flutter SDK to make Flutter development easier and more joyful than ever. GetWi

Jan 1, 2023

Most popular and easy to use open source UI library with 1000+ Widgets to build flutter app.

Most popular and easy to use open source UI library with 1000+ Widgets to build flutter app.

GetWidget is a 100% free Flutter open-source UI Kit library built with Flutter SDK to make Flutter development easier and more joyful than ever. GetWi

Jan 3, 2023

A simple dart zeromq implementation/wrapper around the libzmq C++ library

dartzmq A simple dart zeromq implementation/wrapper around the libzmq C++ library Features Currently supported: Creating sockets (pair, pub, sub, req,

Dec 29, 2022

A wrapper around our Cocoa and Java client library SDKs, providing iOS and Android support for those using Flutter and Dart.

A wrapper around our Cocoa and Java client library SDKs, providing iOS and Android support for those using Flutter and Dart.

Ably Flutter Plugin A Flutter plugin wrapping the ably-cocoa (iOS) and ably-java (Android) client library SDKs for Ably, the platform that powers sync

Dec 13, 2022

The lightweight and powerful wrapper library for Twitter Ads API written in Dart and Flutter 🐦

TODO: Put a short description of the package here that helps potential users know whether this package might be useful for them. Features TODO: List w

Aug 26, 2022

How to get the most value from Dart static analysis

This package is deprecated. Before it was deprecated, it was the way to get analysis options matching those used internally at Google. This was useful

Nov 4, 2022

How to get the most value from Dart static analysis

This package is deprecated. Before it was deprecated, it was the way to get analysis options matching those used internally at Google. This was useful

Nov 4, 2022
Releases(2.3.2)
  • 2.3.2(Jan 4, 2022)

    Please refer to the following release note for the updated contents

    • https://github.com/myConsciousness/json-response/blob/main/CHANGELOG.md
    Source code(tar.gz)
    Source code(zip)
  • 2.3.1(Jan 2, 2022)

    Please refer to the following release note for the updated contents

    • https://github.com/myConsciousness/json-response/blob/main/CHANGELOG.md
    Source code(tar.gz)
    Source code(zip)
  • 2.3.0(Jan 1, 2022)

    Please refer to the following release note for the updated contents

    • https://github.com/myConsciousness/json-response/blob/main/CHANGELOG.md
    Source code(tar.gz)
    Source code(zip)
  • 2.2.0(Jan 1, 2022)

    Please refer to the following release note for the updated contents

    • https://github.com/myConsciousness/json-response/blob/main/CHANGELOG.md
    Source code(tar.gz)
    Source code(zip)
  • 2.1.0(Jan 1, 2022)

    Please refer to the following release note for the updated contents

    • https://github.com/myConsciousness/json-response/blob/main/CHANGELOG.md
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0(Dec 29, 2021)

    Please refer to the following release note for the updated contents

    • https://github.com/myConsciousness/json-response/blob/main/CHANGELOG.md
    Source code(tar.gz)
    Source code(zip)
  • 1.0.2(Dec 27, 2021)

    Please refer to the following release note for the updated contents

    • https://github.com/myConsciousness/json-response/blob/main/CHANGELOG.md
    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Dec 27, 2021)

    Please refer to the following release note for the updated contents

    • https://github.com/myConsciousness/json-response/blob/main/CHANGELOG.md
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Dec 18, 2021)

Owner
Kato Shinya
Freelance software developer. Web and Batch development in Java. Also mobile development in Flutter.
Kato Shinya
A most easily usable Duolingo API wrapper in Dart. Duolingo4D is an open-sourced Dart library.

A most easily usable Duolingo API wrapper in Dart! 1. About Duolingo4D Duolingo4D is an open-sourced Dart library. With Duolingo4D, you can easily int

Kato Shinya 18 Oct 17, 2022
A most easily usable cookie management library in Dart. With SweetCookieJar, you can easily manage cookie on your application.

A most easily usable cookie management library in Dart! 1. About 1.1. Introduction 1.1.1. Install Library 1.1.2. Import It 1.1.3. Use SweetCookieJar 1

Kato Shinya 9 Oct 27, 2022
A most easily usable cache management library in Dart. With CacheStorage, you can easily manage cache on your application.

A most easily usable cache management library in Dart! 1. About 1.1. Introduction 1.1.1. Install Library 1.1.2. Import It 1.1.3. Use CacheStorage 1.2.

Kato Shinya 1 Dec 13, 2021
A most easily usable improvement rate calculator library in Dart.

A most easily usable improvement rate calculator library in Dart. With ImprovementRate, you can easily calculate improvement rate on your application.

Kato Shinya 1 Dec 27, 2021
Given a JSON string, this library will generate all the necessary Dart classes to parse and generate JSON.

JSON to Dart Given a JSON string, this library will generate all the necessary Dart classes to parse and generate JSON. This library is designed to ge

Javier Lecuona 1.2k Dec 25, 2022
State Persistence - Persist state across app launches. By default this library store state as a local JSON file called `data.json` in the applications data directory. Maintainer: @slightfoot

State Persistence Persist state across app launches. By default this library store state as a local JSON file called data.json in the applications dat

Flutter Community 70 Sep 28, 2022
Flutter package: Json Table Widget to create table from json array

Json Table Widget ?? Proudly Sponsored by FieldAssist Request a Demo This Flutter package provides a Json Table Widget for directly showing table from

Ayush P Gupta 193 Jan 7, 2023
Fluter-json - App Demonstrating JSON Data Parsing with various flutter widgets

users_list Flutter App to Demonstrate JSON Parsing Getting Started This project is a starting point for a Flutter application. A few resources to get

Khurram Rizvi 5 Jul 10, 2021
Json editor - A json editor on flutter

Features Support add comment; Support show errors for invalid json text; Pretty

Chan Young 12 Nov 18, 2022
A JSON serialize class to convert 'to' and 'from' JSON format Enums, DateTime and any of your own classes.

A JSON serialize class to convert 'to' and 'from' JSON format Enums, DateTime and any of your own classes. Introduction Jsonize solves the problem of

null 2 Nov 17, 2022