Tool made in Dart that allows you to dynamically generate JSON files from data models written in Dart.

Overview

Dart JSON Generator

Versión v1.1.1

Dart JSON Generator es una herramienta que permite generar archivos JSON a partir de mapas como modelos de datos en el lenguaje Dart en su version v2.18.2 o superior.

¿Como funciona?

Primero debes instalar el SDK de Dart en tu equipo Mac, Linux o Windows. Puedes descargarlo desde aquí.

Nota: Si eres desarrollador Flutter, Dart ya viene instalado en tu equipo.

Luego de instalar Dart, en la terminal de tu IDE de preferencia, debes ejecutar el siguiente comando:

> dart run

Crear modelos de datos

Para crear un modelo de datos debes hacerlo dentro del archivo principal bin/generador_de_json.dart, puedes llamar al metodo generateJson.generateJson() y en su parametro jsonMap debes pasarle un mapa con los datos que deseas convertir a JSON como en el siguiente ejemplo:

generateJson.generateJson(
    jsonName: 'example',
    jsonMap: <String, dynamic>{
        ¨id¨: 1,
        ¨name¨: ¨John Doe¨,
        ¨age¨: 25,
        ¨isDeveloper¨: true,
    }
);

El parametro jsonName es el nombre del archivo JSON que se generará, en este caso el archivo se llamará example.json y se almacenara en la carpeta lib/example.json.

Para generar un archivo JSON con un array de objetos debes hacerlo de la siguiente manera:

generateJson.generateJsonList(
    jsonName: 'test_data',
    jsonMap: (data) {
      return List.generate(
        100, // Cantidad de objetos que se generaran
        (index) => <String, dynamic>{
          'id': index,
          'name': util.generateRandomFemaleOrMaleName(),
          'lastName': util.generateRandomLastName(),
          'email': util.generateRandomEmail(),
          'avatar': util.generateRandomAvatarUrl(),
          'phone': util.generateRandomPhoneNumber(),
          'isShared': util.generateRandomBool(),
        },
      );
    },
  );

En este ejemplo se generará un archivo JSON con 100 objetos con los datos de una persona, también en el ejemplo se esta haciendo uso de la instancia util que es una clase que contiene metodos preestablecidos que generan datos aleatorios como nombres, apellidos, correos, etc.

Si quieres generar tus propios metodos preestablecidos puedes hacerlo editando el archivo lib/utils/all_utils.dart.

Algunos de los metodos preestablecidos de los que puedes hacer uso son:

  • generateRandomBool()
    • Genera un valor booleano aleatorio.
  • generateRandomMaleName()
    • Genera un nombre masculino sin apellido aleatorio, pero si el parametro isFullName es true genera un nombre completo.
  • generateRandomFemaleName()
    • Genera un nombre femenino sin apellido aleatorio, pero si el parametro isFullName es true genera un nombre completo.
  • generateRandomFemaleOrMaleName()
    • Genera un nombre aleatorio masculino o femenino sin apellido, pero si el parametro isFullName es true genera un nombre completo.
  • generateRandomEmail()
    • Genera un correo electronico aleatorio.
  • generateRandomAvatarUrl()
    • Genera una url de una imagen aleatoria masculino o femenino.
  • generateRandomMaleAvatarUrl()
    • Genera una url de una imagen masculina aleatoria.
  • generateRandomFemaleAvatarUrl()
    • Genera una url de una imagen femenina aleatoria.
  • generateRandomPhoneNumber()
    • Genera un numero de telefono aleatorio.
  • generateRandomLastName()
    • Genera un apellido aleatorio.
You might also like...

Flutter package: Json Table Widget to create table from json array

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

Jan 7, 2023

Json editor - A json editor on flutter

Json editor - A json editor on flutter

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

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

Nov 17, 2022

🎯 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

Download files from Firebase Storage with Flutter. List all images, videos, or other files from Firebase and download them.

Download files from Firebase Storage with Flutter. List all images, videos, or other files from Firebase and download them.

Flutter Tutorial - Download Files From Firebase Storage Download files from Firebase Storage with Flutter. List all images, videos, or other files fro

Dec 4, 2022

Upload Files To Firebase Storage with Flutter. Pick images, videos, or other files from your device and upload them to Firebase.

Upload Files To Firebase Storage with Flutter. Pick images, videos, or other files from your device and upload them to Firebase.

Flutter Tutorial - Upload Files To Firebase Storage Upload Files To Firebase Storage with Flutter. Pick images, videos, or other files from your devic

Dec 28, 2022

Dynamically themed Music Player built with flutter

Dynamically themed Music Player built with flutter

🎧 Flutter Music Player Contact me email: [email protected] Gitter: https://gitter.im/Moda20TuneIn/community Thank you in advance 👍 Getting Started

Dec 31, 2022

A Flutter plugin than allow expand and collapse text dynamically

A Flutter plugin than allow expand and collapse text dynamically

readmore A Flutter plugin than allow expand and collapse text. usage: add to your pubspec readmore: ^1.0.2 and import: import 'package:readmore/readm

Dec 28, 2022

A Flutter package used to update widget tree dynamically

A Flutter package used to update widget tree dynamically

简体中文|English Fair is a lightweight package for Flutter, which can be used to update widget tree and state dynamically. This package is still at an ear

Dec 30, 2022
Comments
  • Documentacion y algunas mejoras

    Documentacion y algunas mejoras

    --- Se agrego una documentacion para saber como usar la herramienta --- Se mejoraron los ejemplos en el archivo generador_de_json.dart --- Se crearon dos archivos json como ejemplos --- En la clase generate_json.dart se creo un nuevo metodo para crear json con un solo dato --- Se elimino el json test_data.json --- Se corrigieron los nombres de dos metodos en la clase all_utils.dart

    opened by devjoi2018 0
  • Mejora en el generador

    Mejora en el generador

    --- Se cambio la forma en como se llama el generador de json, ahora recibe mas argumentos y las listas se geenran de una forma distinta --- Se mejoro la documentacion local del codigo agregando algunos ejemplos para que sea mas facil de entender --- Se separo la data en una clase aparte y se agregaron nuevos datos --- Se creo una clase utilidades que contiene todos los metodos disposibles para la generacion de datos personales

    opened by devjoi2018 0
Releases(v1.1.1)
  • v1.1.1(Nov 13, 2022)

    What's Changed

    • Documentacion y algunas mejoras by @devjoi2018 in https://github.com/devjoi2018/dart_generate_json/pull/2

    Full Changelog: https://github.com/devjoi2018/dart_generate_json/compare/v1.0.0...v1.1.1

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Nov 12, 2022)

    What's Changed

    • Mejora en el generador by @devjoi2018 in https://github.com/devjoi2018/dart_generate_json/pull/1

    New Contributors

    • @devjoi2018 made their first contribution in https://github.com/devjoi2018/dart_generate_json/pull/1

    Full Changelog: https://github.com/devjoi2018/dart_generate_json/commits/v-1.0.0

    Source code(tar.gz)
    Source code(zip)
Owner
Joinner Medina
I am a professional technician in microtechnology and graphic designer, currently an Android application programmer with flutter.
Joinner Medina
This is tool to create 3D Models which can be used in Flutter Applications. Tool is developed completely using Flutter.

three_d_model_tool A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you start

Shubham Yeole 2 Nov 8, 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
Displaying json models in a Flutter widget

Displaying json models in a Flutter widget ?? Cool solution for viewing models in debug working Getting Started Add dependency dependencies: flutter

Stanislav Ilin 54 Dec 19, 2022
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
Polymaker is an application that can create polygon locations dynamically in mobile apps and save the data into SQFlite to be permanent.

Polymaker Polymaker is an application that can create polygon locations dynamically in mobile apps and save the data into SQFlite to be permanent. Ins

Yusril Rapsanjani 15 Apr 17, 2022
This is a command-line app written on dart language for flutter applications that will help you to generate some boilerplate code

dart-generator Manual installation: 1- generate a platform executable from code dart compile exe main.dart -o generator this will generate a new gene

One Studio 11 Oct 26, 2022
A Dart validation DSL to validate your flutter app models.

Validations made simple A fp inspired validation DSL. For Dart and Flutter projects. Features Completely extensible (create your own combinators, vali

Daniel Cardona Rojas 26 Feb 8, 2022
An unofficial, platform independent, client for accessing different AI models developed by OpenAI

The OpenAI API can be applied to virtually any task that involves understanding or generating natural language or code. They offer a spectrum of model

Francesco Coppola 14 Dec 30, 2022
A package script for allowing coverage test tool to see all Dart files

full_coverage Coverage tools like codecov only see the files that were actually triggered by tests. This means that a coverage of 100% can easily be a

Flutterando 2 Mar 18, 2022
ToDo App made with flutter which stores your todos based on their categories. The data is stored in external application storage in your device in JSON file.

⭐ My ToDo ⭐ Built with ❤︎ by Akash Debnath This is my second project on Flutter. This app hepls you to keep record of your ToDos. You can create your

Akash Debnath 38 Dec 25, 2022