Git Product home page Git Product logo

json_to_dart's Introduction

JSON to Dart

Build Status

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

This library is designed to generate Flutter friendly model classes following the flutter's doc recommendation.

Caveats

  • When an empty array is given, it will create a List. Such weird behaviour should warn the user that there is no data to extract.
  • Equal structures are not detected yet (Equal classes are going to be created over and over).
  • Properties named with funky names (like "!breaks", "|breaks", etc) or keyword (like "this", "break", "class", etc) will produce syntax errors.
  • Array of arrays are not supported:
[[{ "isThisSupported": false }]]
[{ "thisSupported": [{ "cool": true }] }]

json_to_dart's People

Contributors

javiercbk avatar jonathanbaugusto avatar natoboram avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

json_to_dart's Issues

'List' is deprecated and shouldn't be used.

Warning message:

'List' is deprecated and shouldn't be used. Try replacing the use of the deprecated member with the replacement.

Generated code:

  LocationCoordinate.fromJson(Map<String, dynamic> json) {
    states = json['states'].cast<String>();
    if (json['results'] != null) {
      results = new List<Results>();
      json['results'].forEach((v) {
        results.add(new Results.fromJson(v));
      });
    }
  }

Can this be made into a package?

You can make this into a package, and when you add your package to the flutter project, you create a json file that you want to generate the dart class, and then type the generate command at the terminal to generate the corresponding dart class file

😂I do not know if there is a package with similar functions, I am looking forward to it!!

[request] add option for null handling

hello.

thanks for your great json to dart converter. regarding request, can you create option for null handling? for example, when the input is:

{
    "nopo": "PO00000390",
    "address": "Jl. Jend Sudirman No. 1"
}

the output is:

class Autogenerated {
  String nopo;
  int quantity;

  Autogenerated({this.nopo, this.quantity});

  Autogenerated.fromJson(Map<String, dynamic> json) {
    nopo = json['nopo'] ?? "";
    quantity = json['quantity'] ?? 0;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['nopo'] = this.nopo;
    data['quantity'] = this.quantity;
    return data;
  }
}

thank you

Unable to convert valid json

My json which is asserted valid by jsonlint.com:

[{"mailbox":"ct87ugz5","id":"5cd7baf5cfcdca06a3f07759","from":"hohg8z+dxzd795mt5gns","to":["\"[email protected]\" \[email protected]\u003e"],"subject":"Alstroemeria Record","date":"2019-05-12T14:19:33+08:00","size":1527,"seen":false}]

Error:

TypeError: Instance of 'JSArray': type 'JSArray' is not a subtype of type 'Map<String, dynamic>'

Cannot generate dart code. Please check the project caveats.

myjson response like below but always cannot generate
[
{
"name": "System Management",
"path": "/system",
"redirect": "noredirect",
"component": "Layout",
"alwaysShow": true,
"meta": {
"title": "System Management",
"icon": "system"
},
"children": [
{
"name": "User Management",
"path": "user",
"component": "system/user/index",
"meta": {
"title": "User Management",
"icon": "peoples"
}
},
{
"name": "Role management",
"path": "role",
"component": "system/role/index",
"meta": {
"title": "Role management",
"icon": "role"
}
},
{
"name": "Authority management",
"path": "permission",
"component": "system/permission/index",
"meta": {
"title": "Authority management",
"icon": "permission"
}
},
{
"name": "Menu management",
"path": "menu",
"component": "system/menu/index",
"meta": {
"title": "Menu management",
"icon": "menu"
}
},
{
"name": "Department management",
"path": "dept",
"component": "system/dept/index",
"meta": {
"title": "Department management",
"icon": "dept"
}
},
{
"name": "Job management",
"path": "job",
"component": "system/job/index",
"meta": {
"title": "Job management",
"icon": "Steve-Jobs"
}
},
{
"name": "Dictionary management",
"path": "dict",
"component": "system/dict/index",
"meta": {
"title": "Dictionary management",
"icon": "dictionary"
}
}
]
},
{
"name": "System monitoring",
"path": "/monitor",
"redirect": "noredirect",
"component": "Layout",
"alwaysShow": true,
"meta": {
"title": "System monitoring",
"icon": "monitor"
},
"children": [
{
"name": "Operation log",
"path": "logs",
"component": "monitor/log/index",
"meta": {
"title": "Operation log",
"icon": "log"
}
},
{
"name": "Exception log",
"path": "errorLog",
"component": "monitor/log/errorLog",
"meta": {
"title": "Exception log",
"icon": "error"
}
},
{
"name": "System cache",
"path": "redis",
"component": "monitor/redis/index",
"meta": {
"title": "System cache",
"icon": "redis"
}
},
{
"name": "SQL monitoring",
"path": "druid",
"component": "monitor/sql/index",
"meta": {
"title": "SQL monitoring",
"icon": "sqlMonitor"
}
}
]
},
{
"path": "/logbook",
"component": "Layout",
"children": [
{
"name": "Log Book ",
"path": "index",
"component": "logbook/index",
"meta": {
"title": "Log Book ",
"icon": "tools"
}
}
]
},
{
"name": "Master Data",
"path": "/",
"redirect": "noredirect",
"component": "Layout",
"alwaysShow": true,
"meta": {
"title": "Master Data",
"icon": "tools"
},
"children": [
{
"name": "category",
"path": "category",
"component": "master/category/index",
"meta": {
"title": "category",
"icon": "category"
}
},
{
"name": "item",
"path": "item",
"component": "master/item/index",
"meta": {
"title": "item",
"icon": "sys-tools"
}
}
]
},
{
"name": "System Tool",
"path": "/sys-tools",
"redirect": "noredirect",
"component": "Layout",
"alwaysShow": true,
"meta": {
"title": "System Tool",
"icon": "sys-tools"
},
"children": [
{
"name": "Timed task\r\n",
"path": "timing",
"component": "system/timing/index",
"meta": {
"title": "Timed task\r\n",
"icon": "timing"
}
},
{
"name": "Swagger",
"path": "swagger2",
"component": "tools/swagger/index",
"meta": {
"title": "Swagger",
"icon": "swagger"
}
},
{
"name": "Mail tool",
"path": "email",
"component": "tools/email/index",
"meta": {
"title": "Mail tool",
"icon": "email"
}
},
{
"name": "Image Management",
"path": "pictures",
"component": "tools/picture/index",
"meta": {
"title": "Image Management",
"icon": "image"
}
},
{
"name": "Qiniu cloud storage",
"path": "qiniu",
"component": "tools/qiniu/index",
"meta": {
"title": "Qiniu cloud storage",
"icon": "qiniu"
}
}
]
},
{
"name": "CMS",
"path": "/cms",
"redirect": "noredirect",
"component": "Layout",
"alwaysShow": true,
"meta": {
"title": "CMS",
"icon": "system"
},
"children": [
{
"name": "home",
"path": "home",
"redirect": "noredirect",
"component": "cms/home/index",
"alwaysShow": true,
"meta": {
"title": "home",
"icon": "home"
},
"children": [
{
"name": "corousel",
"path": "corousel",
"component": "cms/home/corousel/index",
"meta": {
"title": "corousel",
"icon": "icon"
}
},
{
"name": "team",
"path": "team",
"component": "cms/home/team/index",
"meta": {
"title": "team",
"icon": "user"
}
}
]
},
{
"name": "gallery",
"path": "gallery",
"component": "cms/gallery/index",
"meta": {
"title": "gallery",
"icon": "image"
}
},
{
"name": "video",
"path": "video",
"component": "cms/video/index",
"meta": {
"title": "video",
"icon": "film-strip"
}
},
{
"name": "news",
"path": "news",
"component": "cms/news/index",
"meta": {
"title": "news",
"icon": "fwb"
}
}
]
},
{
"name": "Problem",
"path": "/problem",
"redirect": "noredirect",
"component": "Layout",
"alwaysShow": true,
"meta": {
"title": "Problem",
"icon": "log"
},
"children": [
{
"name": "List Problem",
"path": "problem list",
"component": "problem/index",
"meta": {
"title": "List Problem",
"icon": "dev"
}
},
{
"name": "Unassigne",
"path": "unassgine",
"component": "problem/index1",
"meta": {
"title": "Unassigne",
"icon": "develop"
}
}
]
},
{
"path": "/jobdesk",
"component": "Layout",
"children": [
{
"name": "Jobdesk",
"path": "index",
"component": "jobdesk/index",
"meta": {
"title": "Jobdesk",
"icon": "monitor"
}
}
]
},
{
"path": "/containeryard",
"component": "Layout",
"children": [
{
"name": "Container Yard",
"path": "index",
"component": "containeryard/index",
"meta": {
"title": "Container Yard",
"icon": "image"
}
}
]
},
{
"path": "/bongkarmuat",
"component": "Layout",
"children": [
{
"name": "Bongkar Muat",
"path": "index",
"component": "bongkarmuat/index",
"meta": {
"title": "Bongkar Muat",
"icon": "codeConsole"
}
}
]
}
]

Allow generating code as a compiler tool

any chance this can be adjusted so it functions as a tool at compile time ?
a bit like other dart generators, where you point it to a directory and it generates the code for you.

you can still have it also work on the web too for.

Missing Parameter type for ('v')

When I paste the code to Android (Android Studio , Visual code ) it throws the following error:
Missing Parameter type for ('v')
The problem is here : json['data'].forEach((v) and also here data['data'] = this.data.map((v) => v.toJson()).toList();

flutter --version
Flutter 1.2.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 8661d8aecd (7 weeks ago) • 2019-02-14 19:19:53 -0800
Engine • revision 3757390fa4
Tools • Dart 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)
class Autogenerated {
  NewOffer newOffer;
  SoldOffer soldOffer;
  HotOffer hotOffer;
  UsedOffer usedOffer;
  List<Countries> countries;
  List<TypeCompany> typeCompany;
  List<TopSearch> topSearch;
  List<Banner> banner;
  Config config;
  List<CompaniesName> companiesName;
  Diff diff;

  Autogenerated(
      {this.newOffer,
      this.soldOffer,
      this.hotOffer,
      this.usedOffer,
      this.countries,
      this.typeCompany,
      this.topSearch,
      this.banner,
      this.config,
      this.companiesName,
      this.diff});

  Autogenerated.fromJson(Map<String, dynamic> json) {
    newOffer = json['newOffer'] != null
        ? new NewOffer.fromJson(json['newOffer'])
        : null;
    soldOffer = json['soldOffer'] != null
        ? new SoldOffer.fromJson(json['soldOffer'])
        : null;
    hotOffer = json['hotOffer'] != null
        ? new HotOffer.fromJson(json['hotOffer'])
        : null;
    usedOffer = json['usedOffer'] != null
        ? new UsedOffer.fromJson(json['usedOffer'])
        : null;
    if (json['countries'] != null) {
      countries = new List<Countries>();
      json['countries'].forEach((v) {
        countries.add(new Countries.fromJson(v));
      });
    }
    if (json['typeCompany'] != null) {
      typeCompany = new List<TypeCompany>();
      json['typeCompany'].forEach((v) {
        typeCompany.add(new TypeCompany.fromJson(v));
      });
    }
    if (json['topSearch'] != null) {
      topSearch = new List<TopSearch>();
      json['topSearch'].forEach((v) {
        topSearch.add(new TopSearch.fromJson(v));
      });
    }
    if (json['banner'] != null) {
      banner = new List<Banner>();
      json['banner'].forEach((v) {
        banner.add(new Banner.fromJson(v));
      });
    }
    config =
        json['config'] != null ? new Config.fromJson(json['config']) : null;
    if (json['companiesName'] != null) {
      companiesName = new List<CompaniesName>();
      json['companiesName'].forEach((v) {
        companiesName.add(new CompaniesName.fromJson(v));
      });
    }
    diff = json['diff'] != null ? new Diff.fromJson(json['diff']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.newOffer != null) {
      data['newOffer'] = this.newOffer.toJson();
    }
    if (this.soldOffer != null) {
      data['soldOffer'] = this.soldOffer.toJson();
    }
    if (this.hotOffer != null) {
      data['hotOffer'] = this.hotOffer.toJson();
    }
    if (this.usedOffer != null) {
      data['usedOffer'] = this.usedOffer.toJson();
    }
    if (this.countries != null) {
      data['countries'] = this.countries.map((v) => v.toJson()).toList();
    }
    if (this.typeCompany != null) {
      data['typeCompany'] = this.typeCompany.map((v) => v.toJson()).toList();
    }
    if (this.topSearch != null) {
      data['topSearch'] = this.topSearch.map((v) => v.toJson()).toList();
    }
    if (this.banner != null) {
      data['banner'] = this.banner.map((v) => v.toJson()).toList();
    }
    if (this.config != null) {
      data['config'] = this.config.toJson();
    }
    if (this.companiesName != null) {
      data['companiesName'] =
          this.companiesName.map((v) => v.toJson()).toList();
    }
    if (this.diff != null) {
      data['diff'] = this.diff.toJson();
    }
    return data;
  }
}

class NewOffer {
  int currentPage;
  List<Data> data;
  String firstPageUrl;
  int from;
  int lastPage;
  String lastPageUrl;
  Null nextPageUrl;
  String path;
  int perPage;
  Null prevPageUrl;
  int to;
  int total;

  NewOffer(
      {this.currentPage,
      this.data,
      this.firstPageUrl,
      this.from,
      this.lastPage,
      this.lastPageUrl,
      this.nextPageUrl,
      this.path,
      this.perPage,
      this.prevPageUrl,
      this.to,
      this.total});

  NewOffer.fromJson(Map<String, dynamic> json) {
    currentPage = json['current_page'];
    if (json['data'] != null) {
      data = new List<Data>();
      json['data'].forEach((v) {
        data.add(new Data.fromJson(v));
      });
    }
    firstPageUrl = json['first_page_url'];
    from = json['from'];
    lastPage = json['last_page'];
    lastPageUrl = json['last_page_url'];
    nextPageUrl = json['next_page_url'];
    path = json['path'];
    perPage = json['per_page'];
    prevPageUrl = json['prev_page_url'];
    to = json['to'];
    total = json['total'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['current_page'] = this.currentPage;
    if (this.data != null) {
      data['data'] = this.data.map((v) => v.toJson()).toList();
    }
    data['first_page_url'] = this.firstPageUrl;
    data['from'] = this.from;
    data['last_page'] = this.lastPage;
    data['last_page_url'] = this.lastPageUrl;
    data['next_page_url'] = this.nextPageUrl;
    data['path'] = this.path;
    data['per_page'] = this.perPage;
    data['prev_page_url'] = this.prevPageUrl;
    data['to'] = this.to;
    data['total'] = this.total;
    return data;
  }
}

class Data {
  int id;
  int companyId;
  int userId;
  String offerType;
  int isSold;
  int isAuction;
  int priceBefore;
  int priceAfter;
  String text;
  String endDate;
  int active;
  String updatedAt;
  String createdAt;
  String city;
  int sort;
  int state;
  int view;
  List<Images> images;
  List<SimilarOffer> similarOffer;
  Company company;
  List<OfferFeedBack> offerFeedBack;
  Rating rating;
  List<Specifications> specifications;

  Data(
      {this.id,
      this.companyId,
      this.userId,
      this.offerType,
      this.isSold,
      this.isAuction,
      this.priceBefore,
      this.priceAfter,
      this.text,
      this.endDate,
      this.active,
      this.updatedAt,
      this.createdAt,
      this.city,
      this.sort,
      this.state,
      this.view,
      this.images,
      this.similarOffer,
      this.company,
      this.offerFeedBack,
      this.rating,
      this.specifications});

  Data.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    companyId = json['company_id'];
    userId = json['user_id'];
    offerType = json['offer_type'];
    isSold = json['is_sold'];
    isAuction = json['is_auction'];
    priceBefore = json['price_before'];
    priceAfter = json['price_after'];
    text = json['text'];
    endDate = json['end_date'];
    active = json['active'];
    updatedAt = json['updated_at'];
    createdAt = json['created_at'];
    city = json['city'];
    sort = json['sort'];
    state = json['state'];
    view = json['view'];
    if (json['images'] != null) {
      images = new List<Images>();
      json['images'].forEach((v) {
        images.add(new Images.fromJson(v));
      });
    }
    if (json['similar_offer'] != null) {
      similarOffer = new List<SimilarOffer>();
      json['similar_offer'].forEach((v) {
        similarOffer.add(new SimilarOffer.fromJson(v));
      });
    }
    company =
        json['company'] != null ? new Company.fromJson(json['company']) : null;
    if (json['offer_feed_back'] != null) {
      offerFeedBack = new List<OfferFeedBack>();
      json['offer_feed_back'].forEach((v) {
        offerFeedBack.add(new OfferFeedBack.fromJson(v));
      });
    }
    rating =
        json['rating'] != null ? new Rating.fromJson(json['rating']) : null;
    if (json['specifications'] != null) {
      specifications = new List<Specifications>();
      json['specifications'].forEach((v) {
        specifications.add(new Specifications.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['company_id'] = this.companyId;
    data['user_id'] = this.userId;
    data['offer_type'] = this.offerType;
    data['is_sold'] = this.isSold;
    data['is_auction'] = this.isAuction;
    data['price_before'] = this.priceBefore;
    data['price_after'] = this.priceAfter;
    data['text'] = this.text;
    data['end_date'] = this.endDate;
    data['active'] = this.active;
    data['updated_at'] = this.updatedAt;
    data['created_at'] = this.createdAt;
    data['city'] = this.city;
    data['sort'] = this.sort;
    data['state'] = this.state;
    data['view'] = this.view;
    if (this.images != null) {
      data['images'] = this.images.map((v) => v.toJson()).toList();
    }
    if (this.similarOffer != null) {
      data['similar_offer'] = this.similarOffer.map((v) => v.toJson()).toList();
    }
    if (this.company != null) {
      data['company'] = this.company.toJson();
    }
    if (this.offerFeedBack != null) {
      data['offer_feed_back'] =
          this.offerFeedBack.map((v) => v.toJson()).toList();
    }
    if (this.rating != null) {
      data['rating'] = this.rating.toJson();
    }
    if (this.specifications != null) {
      data['specifications'] =
          this.specifications.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class Images {
  int id;
  int offerId;
  String path;
  String createdAt;
  Null updatedAt;

  Images({this.id, this.offerId, this.path, this.createdAt, this.updatedAt});

  Images.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    offerId = json['offer_id'];
    path = json['path'];
    createdAt = json['created_at'];
    updatedAt = json['updated_at'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['offer_id'] = this.offerId;
    data['path'] = this.path;
    data['created_at'] = this.createdAt;
    data['updated_at'] = this.updatedAt;
    return data;
  }
}

class SimilarOffer {
  int id;
  int companyId;
  int userId;
  String offerType;
  int isSold;
  int isAuction;
  int priceBefore;
  int priceAfter;
  String text;
  String endDate;
  int active;
  String updatedAt;
  String createdAt;
  String city;
  int sort;
  int state;
  int view;
  List<Images> images;
  Company company;
  List<OfferFeedBack> offerFeedBack;
  List<Specifications> specifications;
  Rating rating;

  SimilarOffer(
      {this.id,
      this.companyId,
      this.userId,
      this.offerType,
      this.isSold,
      this.isAuction,
      this.priceBefore,
      this.priceAfter,
      this.text,
      this.endDate,
      this.active,
      this.updatedAt,
      this.createdAt,
      this.city,
      this.sort,
      this.state,
      this.view,
      this.images,
      this.company,
      this.offerFeedBack,
      this.specifications,
      this.rating});

  SimilarOffer.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    companyId = json['company_id'];
    userId = json['user_id'];
    offerType = json['offer_type'];
    isSold = json['is_sold'];
    isAuction = json['is_auction'];
    priceBefore = json['price_before'];
    priceAfter = json['price_after'];
    text = json['text'];
    endDate = json['end_date'];
    active = json['active'];
    updatedAt = json['updated_at'];
    createdAt = json['created_at'];
    city = json['city'];
    sort = json['sort'];
    state = json['state'];
    view = json['view'];
    if (json['images'] != null) {
      images = new List<Images>();
      json['images'].forEach((v) {
        images.add(new Images.fromJson(v));
      });
    }
    company =
        json['company'] != null ? new Company.fromJson(json['company']) : null;
    if (json['offer_feed_back'] != null) {
      offerFeedBack = new List<OfferFeedBack>();
      json['offer_feed_back'].forEach((v) {
        offerFeedBack.add(new OfferFeedBack.fromJson(v));
      });
    }
    if (json['specifications'] != null) {
      specifications = new List<Specifications>();
      json['specifications'].forEach((v) {
        specifications.add(new Specifications.fromJson(v));
      });
    }
    rating =
        json['rating'] != null ? new Rating.fromJson(json['rating']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['company_id'] = this.companyId;
    data['user_id'] = this.userId;
    data['offer_type'] = this.offerType;
    data['is_sold'] = this.isSold;
    data['is_auction'] = this.isAuction;
    data['price_before'] = this.priceBefore;
    data['price_after'] = this.priceAfter;
    data['text'] = this.text;
    data['end_date'] = this.endDate;
    data['active'] = this.active;
    data['updated_at'] = this.updatedAt;
    data['created_at'] = this.createdAt;
    data['city'] = this.city;
    data['sort'] = this.sort;
    data['state'] = this.state;
    data['view'] = this.view;
    if (this.images != null) {
      data['images'] = this.images.map((v) => v.toJson()).toList();
    }
    if (this.company != null) {
      data['company'] = this.company.toJson();
    }
    if (this.offerFeedBack != null) {
      data['offer_feed_back'] =
          this.offerFeedBack.map((v) => v.toJson()).toList();
    }
    if (this.specifications != null) {
      data['specifications'] =
          this.specifications.map((v) => v.toJson()).toList();
    }
    if (this.rating != null) {
      data['rating'] = this.rating.toJson();
    }
    return data;
  }
}

class Company {
  int id;
  String name;
  String logo;
  String mobile;
  int userId;
  int companyTypeId;
  Null createdAt;
  Null updatedAt;
  String facadeUrl;
  List<CompanyBranches> companyBranches;

  Company(
      {this.id,
      this.name,
      this.logo,
      this.mobile,
      this.userId,
      this.companyTypeId,
      this.createdAt,
      this.updatedAt,
      this.facadeUrl,
      this.companyBranches});

  Company.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
    logo = json['logo'];
    mobile = json['mobile'];
    userId = json['user_id'];
    companyTypeId = json['company_type_id'];
    createdAt = json['created_at'];
    updatedAt = json['updated_at'];
    facadeUrl = json['facade_url'];
    if (json['company_branches'] != null) {
      companyBranches = new List<CompanyBranches>();
      json['company_branches'].forEach((v) {
        companyBranches.add(new CompanyBranches.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['name'] = this.name;
    data['logo'] = this.logo;
    data['mobile'] = this.mobile;
    data['user_id'] = this.userId;
    data['company_type_id'] = this.companyTypeId;
    data['created_at'] = this.createdAt;
    data['updated_at'] = this.updatedAt;
    data['facade_url'] = this.facadeUrl;
    if (this.companyBranches != null) {
      data['company_branches'] =
          this.companyBranches.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class CompanyBranches {
  int id;
  int companyId;
  String address;
  String phone;
  String city;
  String area;
  Null updatedAt;
  Null createdAt;

  CompanyBranches(
      {this.id,
      this.companyId,
      this.address,
      this.phone,
      this.city,
      this.area,
      this.updatedAt,
      this.createdAt});

  CompanyBranches.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    companyId = json['company_id'];
    address = json['address'];
    phone = json['phone'];
    city = json['city'];
    area = json['area'];
    updatedAt = json['updated_at'];
    createdAt = json['created_at'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['company_id'] = this.companyId;
    data['address'] = this.address;
    data['phone'] = this.phone;
    data['city'] = this.city;
    data['area'] = this.area;
    data['updated_at'] = this.updatedAt;
    data['created_at'] = this.createdAt;
    return data;
  }
}

class OfferFeedBack {
  int id;
  int offerId;
  int userId;
  String feedback;
  String createdAt;
  Null updatedAt;
  User user;

  OfferFeedBack(
      {this.id,
      this.offerId,
      this.userId,
      this.feedback,
      this.createdAt,
      this.updatedAt,
      this.user});

  OfferFeedBack.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    offerId = json['offer_id'];
    userId = json['user_id'];
    feedback = json['feedback'];
    createdAt = json['created_at'];
    updatedAt = json['updated_at'];
    user = json['user'] != null ? new User.fromJson(json['user']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['offer_id'] = this.offerId;
    data['user_id'] = this.userId;
    data['feedback'] = this.feedback;
    data['created_at'] = this.createdAt;
    data['updated_at'] = this.updatedAt;
    if (this.user != null) {
      data['user'] = this.user.toJson();
    }
    return data;
  }
}

class User {
  int id;
  String username;
  String imageUrl;

  User({this.id, this.username, this.imageUrl});

  User.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    username = json['username'];
    imageUrl = json['image_url'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['username'] = this.username;
    data['image_url'] = this.imageUrl;
    return data;
  }
}

class Specifications {
  int id;
  int specificationsId;
  String val;
  int offerId;
  Null updatedAt;
  Null createdAt;
  SpecificationsType specificationsType;

  Specifications(
      {this.id,
      this.specificationsId,
      this.val,
      this.offerId,
      this.updatedAt,
      this.createdAt,
      this.specificationsType});

  Specifications.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    specificationsId = json['specifications_id'];
    val = json['val'];
    offerId = json['offer_id'];
    updatedAt = json['updated_at'];
    createdAt = json['created_at'];
    specificationsType = json['specifications_type'] != null
        ? new SpecificationsType.fromJson(json['specifications_type'])
        : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['specifications_id'] = this.specificationsId;
    data['val'] = this.val;
    data['offer_id'] = this.offerId;
    data['updated_at'] = this.updatedAt;
    data['created_at'] = this.createdAt;
    if (this.specificationsType != null) {
      data['specifications_type'] = this.specificationsType.toJson();
    }
    return data;
  }
}

class SpecificationsType {
  int id;
  String specificationsType;
  String specificationsIcon;
  int companyTypeId;
  Null updatedAt;
  String createdAt;

  SpecificationsType(
      {this.id,
      this.specificationsType,
      this.specificationsIcon,
      this.companyTypeId,
      this.updatedAt,
      this.createdAt});

  SpecificationsType.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    specificationsType = json['specifications_type'];
    specificationsIcon = json['specifications_icon'];
    companyTypeId = json['company_type_id'];
    updatedAt = json['updated_at'];
    createdAt = json['created_at'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['specifications_type'] = this.specificationsType;
    data['specifications_icon'] = this.specificationsIcon;
    data['company_type_id'] = this.companyTypeId;
    data['updated_at'] = this.updatedAt;
    data['created_at'] = this.createdAt;
    return data;
  }
}

class Rating {
  int offerId;
  double raiting;

  Rating({this.offerId, this.raiting});

  Rating.fromJson(Map<String, dynamic> json) {
    offerId = json['offer_id'];
    raiting = json['raiting'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['offer_id'] = this.offerId;
    data['raiting'] = this.raiting;
    return data;
  }
}

class SoldOffer {
  int currentPage;
  List<Data> data;
  String firstPageUrl;
  int from;
  int lastPage;
  String lastPageUrl;
  Null nextPageUrl;
  String path;
  int perPage;
  Null prevPageUrl;
  int to;
  int total;

  SoldOffer(
      {this.currentPage,
      this.data,
      this.firstPageUrl,
      this.from,
      this.lastPage,
      this.lastPageUrl,
      this.nextPageUrl,
      this.path,
      this.perPage,
      this.prevPageUrl,
      this.to,
      this.total});

  SoldOffer.fromJson(Map<String, dynamic> json) {
    currentPage = json['current_page'];
    if (json['data'] != null) {
      data = new List<Data>();
      json['data'].forEach((v) {
        data.add(new Data.fromJson(v));
      });
    }
    firstPageUrl = json['first_page_url'];
    from = json['from'];
    lastPage = json['last_page'];
    lastPageUrl = json['last_page_url'];
    nextPageUrl = json['next_page_url'];
    path = json['path'];
    perPage = json['per_page'];
    prevPageUrl = json['prev_page_url'];
    to = json['to'];
    total = json['total'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['current_page'] = this.currentPage;
    if (this.data != null) {
      data['data'] = this.data.map((v) => v.toJson()).toList();
    }
    data['first_page_url'] = this.firstPageUrl;
    data['from'] = this.from;
    data['last_page'] = this.lastPage;
    data['last_page_url'] = this.lastPageUrl;
    data['next_page_url'] = this.nextPageUrl;
    data['path'] = this.path;
    data['per_page'] = this.perPage;
    data['prev_page_url'] = this.prevPageUrl;
    data['to'] = this.to;
    data['total'] = this.total;
    return data;
  }
}

class Data {
  int id;
  int companyId;
  int userId;
  String offerType;
  int isSold;
  int isAuction;
  int priceBefore;
  int priceAfter;
  String text;
  String endDate;
  int active;
  String updatedAt;
  String createdAt;
  String city;
  int sort;
  int state;
  int view;
  List<Images> images;
  List<SimilarOffer> similarOffer;
  Company company;
  List<Null> offerFeedBack;
  Null rating;
  List<Null> specifications;

  Data(
      {this.id,
      this.companyId,
      this.userId,
      this.offerType,
      this.isSold,
      this.isAuction,
      this.priceBefore,
      this.priceAfter,
      this.text,
      this.endDate,
      this.active,
      this.updatedAt,
      this.createdAt,
      this.city,
      this.sort,
      this.state,
      this.view,
      this.images,
      this.similarOffer,
      this.company,
      this.offerFeedBack,
      this.rating,
      this.specifications});

  Data.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    companyId = json['company_id'];
    userId = json['user_id'];
    offerType = json['offer_type'];
    isSold = json['is_sold'];
    isAuction = json['is_auction'];
    priceBefore = json['price_before'];
    priceAfter = json['price_after'];
    text = json['text'];
    endDate = json['end_date'];
    active = json['active'];
    updatedAt = json['updated_at'];
    createdAt = json['created_at'];
    city = json['city'];
    sort = json['sort'];
    state = json['state'];
    view = json['view'];
    if (json['images'] != null) {
      images = new List<Images>();
      json['images'].forEach((v) {
        images.add(new Images.fromJson(v));
      });
    }
    if (json['similar_offer'] != null) {
      similarOffer = new List<SimilarOffer>();
      json['similar_offer'].forEach((v) {
        similarOffer.add(new SimilarOffer.fromJson(v));
      });
    }
    company =
        json['company'] != null ? new Company.fromJson(json['company']) : null;
    if (json['offer_feed_back'] != null) {
      offerFeedBack = new List<Null>();
      json['offer_feed_back'].forEach((v) {
        offerFeedBack.add(new Null.fromJson(v));
      });
    }
    rating = json['rating'];
    if (json['specifications'] != null) {
      specifications = new List<Null>();
      json['specifications'].forEach((v) {
        specifications.add(new Null.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['company_id'] = this.companyId;
    data['user_id'] = this.userId;
    data['offer_type'] = this.offerType;
    data['is_sold'] = this.isSold;
    data['is_auction'] = this.isAuction;
    data['price_before'] = this.priceBefore;
    data['price_after'] = this.priceAfter;
    data['text'] = this.text;
    data['end_date'] = this.endDate;
    data['active'] = this.active;
    data['updated_at'] = this.updatedAt;
    data['created_at'] = this.createdAt;
    data['city'] = this.city;
    data['sort'] = this.sort;
    data['state'] = this.state;
    data['view'] = this.view;
    if (this.images != null) {
      data['images'] = this.images.map((v) => v.toJson()).toList();
    }
    if (this.similarOffer != null) {
      data['similar_offer'] = this.similarOffer.map((v) => v.toJson()).toList();
    }
    if (this.company != null) {
      data['company'] = this.company.toJson();
    }
    if (this.offerFeedBack != null) {
      data['offer_feed_back'] =
          this.offerFeedBack.map((v) => v.toJson()).toList();
    }
    data['rating'] = this.rating;
    if (this.specifications != null) {
      data['specifications'] =
          this.specifications.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class SimilarOffer {
  int id;
  int companyId;
  int userId;
  String offerType;
  int isSold;
  int isAuction;
  int priceBefore;
  int priceAfter;
  String text;
  String endDate;
  int active;
  String updatedAt;
  String createdAt;
  String city;
  int sort;
  int state;
  int view;
  List<Images> images;
  Company company;
  List<Null> offerFeedBack;
  List<Null> specifications;
  Null rating;

  SimilarOffer(
      {this.id,
      this.companyId,
      this.userId,
      this.offerType,
      this.isSold,
      this.isAuction,
      this.priceBefore,
      this.priceAfter,
      this.text,
      this.endDate,
      this.active,
      this.updatedAt,
      this.createdAt,
      this.city,
      this.sort,
      this.state,
      this.view,
      this.images,
      this.company,
      this.offerFeedBack,
      this.specifications,
      this.rating});

  SimilarOffer.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    companyId = json['company_id'];
    userId = json['user_id'];
    offerType = json['offer_type'];
    isSold = json['is_sold'];
    isAuction = json['is_auction'];
    priceBefore = json['price_before'];
    priceAfter = json['price_after'];
    text = json['text'];
    endDate = json['end_date'];
    active = json['active'];
    updatedAt = json['updated_at'];
    createdAt = json['created_at'];
    city = json['city'];
    sort = json['sort'];
    state = json['state'];
    view = json['view'];
    if (json['images'] != null) {
      images = new List<Images>();
      json['images'].forEach((v) {
        images.add(new Images.fromJson(v));
      });
    }
    company =
        json['company'] != null ? new Company.fromJson(json['company']) : null;
    if (json['offer_feed_back'] != null) {
      offerFeedBack = new List<Null>();
      json['offer_feed_back'].forEach((v) {
        offerFeedBack.add(new Null.fromJson(v));
      });
    }
    if (json['specifications'] != null) {
      specifications = new List<Null>();
      json['specifications'].forEach((v) {
        specifications.add(new Null.fromJson(v));
      });
    }
    rating = json['rating'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['company_id'] = this.companyId;
    data['user_id'] = this.userId;
    data['offer_type'] = this.offerType;
    data['is_sold'] = this.isSold;
    data['is_auction'] = this.isAuction;
    data['price_before'] = this.priceBefore;
    data['price_after'] = this.priceAfter;
    data['text'] = this.text;
    data['end_date'] = this.endDate;
    data['active'] = this.active;
    data['updated_at'] = this.updatedAt;
    data['created_at'] = this.createdAt;
    data['city'] = this.city;
    data['sort'] = this.sort;
    data['state'] = this.state;
    data['view'] = this.view;
    if (this.images != null) {
      data['images'] = this.images.map((v) => v.toJson()).toList();
    }
    if (this.company != null) {
      data['company'] = this.company.toJson();
    }
    if (this.offerFeedBack != null) {
      data['offer_feed_back'] =
          this.offerFeedBack.map((v) => v.toJson()).toList();
    }
    if (this.specifications != null) {
      data['specifications'] =
          this.specifications.map((v) => v.toJson()).toList();
    }
    data['rating'] = this.rating;
    return data;
  }
}

class HotOffer {
  int currentPage;
  List<Data> data;
  String firstPageUrl;
  int from;
  int lastPage;
  String lastPageUrl;
  Null nextPageUrl;
  String path;
  int perPage;
  Null prevPageUrl;
  int to;
  int total;

  HotOffer(
      {this.currentPage,
      this.data,
      this.firstPageUrl,
      this.from,
      this.lastPage,
      this.lastPageUrl,
      this.nextPageUrl,
      this.path,
      this.perPage,
      this.prevPageUrl,
      this.to,
      this.total});

  HotOffer.fromJson(Map<String, dynamic> json) {
    currentPage = json['current_page'];
    if (json['data'] != null) {
      data = new List<Data>();
      json['data'].forEach((v) {
        data.add(new Data.fromJson(v));
      });
    }
    firstPageUrl = json['first_page_url'];
    from = json['from'];
    lastPage = json['last_page'];
    lastPageUrl = json['last_page_url'];
    nextPageUrl = json['next_page_url'];
    path = json['path'];
    perPage = json['per_page'];
    prevPageUrl = json['prev_page_url'];
    to = json['to'];
    total = json['total'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['current_page'] = this.currentPage;
    if (this.data != null) {
      data['data'] = this.data.map((v) => v.toJson()).toList();
    }
    data['first_page_url'] = this.firstPageUrl;
    data['from'] = this.from;
    data['last_page'] = this.lastPage;
    data['last_page_url'] = this.lastPageUrl;
    data['next_page_url'] = this.nextPageUrl;
    data['path'] = this.path;
    data['per_page'] = this.perPage;
    data['prev_page_url'] = this.prevPageUrl;
    data['to'] = this.to;
    data['total'] = this.total;
    return data;
  }
}

class UsedOffer {
  int currentPage;
  List<Data> data;
  String firstPageUrl;
  int from;
  int lastPage;
  String lastPageUrl;
  Null nextPageUrl;
  String path;
  int perPage;
  Null prevPageUrl;
  int to;
  int total;

  UsedOffer(
      {this.currentPage,
      this.data,
      this.firstPageUrl,
      this.from,
      this.lastPage,
      this.lastPageUrl,
      this.nextPageUrl,
      this.path,
      this.perPage,
      this.prevPageUrl,
      this.to,
      this.total});

  UsedOffer.fromJson(Map<String, dynamic> json) {
    currentPage = json['current_page'];
    if (json['data'] != null) {
      data = new List<Data>();
      json['data'].forEach((v) {
        data.add(new Data.fromJson(v));
      });
    }
    firstPageUrl = json['first_page_url'];
    from = json['from'];
    lastPage = json['last_page'];
    lastPageUrl = json['last_page_url'];
    nextPageUrl = json['next_page_url'];
    path = json['path'];
    perPage = json['per_page'];
    prevPageUrl = json['prev_page_url'];
    to = json['to'];
    total = json['total'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['current_page'] = this.currentPage;
    if (this.data != null) {
      data['data'] = this.data.map((v) => v.toJson()).toList();
    }
    data['first_page_url'] = this.firstPageUrl;
    data['from'] = this.from;
    data['last_page'] = this.lastPage;
    data['last_page_url'] = this.lastPageUrl;
    data['next_page_url'] = this.nextPageUrl;
    data['path'] = this.path;
    data['per_page'] = this.perPage;
    data['prev_page_url'] = this.prevPageUrl;
    data['to'] = this.to;
    data['total'] = this.total;
    return data;
  }
}

class Countries {
  int id;
  String country;
  Null updatedAt;
  String createdAt;
  List<Cities> cities;

  Countries(
      {this.id, this.country, this.updatedAt, this.createdAt, this.cities});

  Countries.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    country = json['country'];
    updatedAt = json['updated_at'];
    createdAt = json['created_at'];
    if (json['cities'] != null) {
      cities = new List<Cities>();
      json['cities'].forEach((v) {
        cities.add(new Cities.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['country'] = this.country;
    data['updated_at'] = this.updatedAt;
    data['created_at'] = this.createdAt;
    if (this.cities != null) {
      data['cities'] = this.cities.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class Cities {
  int id;
  String city;
  String country;
  String updatedAt;
  Null createdAt;
  List<Areas> areas;

  Cities(
      {this.id,
      this.city,
      this.country,
      this.updatedAt,
      this.createdAt,
      this.areas});

  Cities.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    city = json['city'];
    country = json['country'];
    updatedAt = json['updated_at'];
    createdAt = json['created_at'];
    if (json['areas'] != null) {
      areas = new List<Areas>();
      json['areas'].forEach((v) {
        areas.add(new Areas.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['city'] = this.city;
    data['country'] = this.country;
    data['updated_at'] = this.updatedAt;
    data['created_at'] = this.createdAt;
    if (this.areas != null) {
      data['areas'] = this.areas.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class Areas {
  int id;
  String area;
  String city;
  Null updatedAt;
  Null createdAt;

  Areas({this.id, this.area, this.city, this.updatedAt, this.createdAt});

  Areas.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    area = json['area'];
    city = json['city'];
    updatedAt = json['updated_at'];
    createdAt = json['created_at'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['area'] = this.area;
    data['city'] = this.city;
    data['updated_at'] = this.updatedAt;
    data['created_at'] = this.createdAt;
    return data;
  }
}

class TypeCompany {
  int id;
  String companyType;
  String companyTypeIcon;
  Null updatedAt;
  Null createdAt;
  List<TypeOffers> typeOffers;
  List<SpecificationsType> specificationsType;

  TypeCompany(
      {this.id,
      this.companyType,
      this.companyTypeIcon,
      this.updatedAt,
      this.createdAt,
      this.typeOffers,
      this.specificationsType});

  TypeCompany.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    companyType = json['company_type'];
    companyTypeIcon = json['company_type_icon'];
    updatedAt = json['updated_at'];
    createdAt = json['created_at'];
    if (json['type_offers'] != null) {
      typeOffers = new List<TypeOffers>();
      json['type_offers'].forEach((v) {
        typeOffers.add(new TypeOffers.fromJson(v));
      });
    }
    if (json['specifications_type'] != null) {
      specificationsType = new List<SpecificationsType>();
      json['specifications_type'].forEach((v) {
        specificationsType.add(new SpecificationsType.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['company_type'] = this.companyType;
    data['company_type_icon'] = this.companyTypeIcon;
    data['updated_at'] = this.updatedAt;
    data['created_at'] = this.createdAt;
    if (this.typeOffers != null) {
      data['type_offers'] = this.typeOffers.map((v) => v.toJson()).toList();
    }
    if (this.specificationsType != null) {
      data['specifications_type'] =
          this.specificationsType.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class TypeOffers {
  int id;
  String offerType;
  int companyTypeId;
  Null updatedAt;
  Null createdAt;

  TypeOffers(
      {this.id,
      this.offerType,
      this.companyTypeId,
      this.updatedAt,
      this.createdAt});

  TypeOffers.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    offerType = json['offer_type'];
    companyTypeId = json['company_type_id'];
    updatedAt = json['updated_at'];
    createdAt = json['created_at'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['offer_type'] = this.offerType;
    data['company_type_id'] = this.companyTypeId;
    data['updated_at'] = this.updatedAt;
    data['created_at'] = this.createdAt;
    return data;
  }
}

class TopSearch {
  String searchText;
  int count;

  TopSearch({this.searchText, this.count});

  TopSearch.fromJson(Map<String, dynamic> json) {
    searchText = json['search_text'];
    count = json['count'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['search_text'] = this.searchText;
    data['count'] = this.count;
    return data;
  }
}

class Banner {
  int id;
  int companyId;
  Null updatedAt;
  Null createdAt;
  String name;
  String logo;
  String mobile;
  int userId;
  int companyTypeId;
  String facadeUrl;

  Banner(
      {this.id,
      this.companyId,
      this.updatedAt,
      this.createdAt,
      this.name,
      this.logo,
      this.mobile,
      this.userId,
      this.companyTypeId,
      this.facadeUrl});

  Banner.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    companyId = json['company_id'];
    updatedAt = json['updated_at'];
    createdAt = json['created_at'];
    name = json['name'];
    logo = json['logo'];
    mobile = json['mobile'];
    userId = json['user_id'];
    companyTypeId = json['company_type_id'];
    facadeUrl = json['facade_url'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['company_id'] = this.companyId;
    data['updated_at'] = this.updatedAt;
    data['created_at'] = this.createdAt;
    data['name'] = this.name;
    data['logo'] = this.logo;
    data['mobile'] = this.mobile;
    data['user_id'] = this.userId;
    data['company_type_id'] = this.companyTypeId;
    data['facade_url'] = this.facadeUrl;
    return data;
  }
}

class Config {
  int isViews;
  int isMotionEffect;
  String color;
  int vestionCode;
  String motionUrl;
  int isShouldUpdate;

  Config(
      {this.isViews,
      this.isMotionEffect,
      this.color,
      this.vestionCode,
      this.motionUrl,
      this.isShouldUpdate});

  Config.fromJson(Map<String, dynamic> json) {
    isViews = json['is_views'];
    isMotionEffect = json['is_motion_effect'];
    color = json['color'];
    vestionCode = json['vestion_code'];
    motionUrl = json['motion_url'];
    isShouldUpdate = json['is_should_update'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['is_views'] = this.isViews;
    data['is_motion_effect'] = this.isMotionEffect;
    data['color'] = this.color;
    data['vestion_code'] = this.vestionCode;
    data['motion_url'] = this.motionUrl;
    data['is_should_update'] = this.isShouldUpdate;
    return data;
  }
}

class CompaniesName {
  String name;

  CompaniesName({this.name});

  CompaniesName.fromJson(Map<String, dynamic> json) {
    name = json['name'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['name'] = this.name;
    return data;
  }
}

class Diff {
  String endDate;
  int diff;

  Diff({this.endDate, this.diff});

  Diff.fromJson(Map<String, dynamic> json) {
    endDate = json['end_date'];
    diff = json['diff'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['end_date'] = this.endDate;
    data['diff'] = this.diff;
    return data;
  }
}

Add a trailing comma

Thanks for your tools. Would be nice to always add a trailing comma, which is the standard in Dart.

Example:

{
    "tags": [
        "flutter"
    ],
    "owner": {
        "reputation": 354,
        "user_id": 6324029,
        "user_type": "registered",
        "profile_image": "https://www.gravatar.com/avatar/293ab6d0d3810adb641b0d37b800f774?s=128&d=identicon&r=PG&f=1",
        "display_name": "hoangquyy",
        "link": "https://stackoverflow.com/users/6324029/hoangquyy"
    },
    "is_answered": false,
    "view_count": 6,
    "answer_count": 1,
    "score": 0,
    "last_activity_date": 1574754851,
    "creation_date": 1574754058,
    "question_id": 59045950,
    "link": "https://stackoverflow.com/questions/59045950/can-we-download-video-and-play-it-with-flutter-without-add-it-into-asset",
    "title": "Can we download video and play it with flutter without add it into asset?"
}

Should write (basically adding a , after this.link

  Owner({
    this.reputation,
    this.userId,
    this.userType,
    this.profileImage,
    this.displayName,
    this.link,
  });

instead of:

Owner(
      {this.reputation,
      this.userId,
      this.userType,
      this.profileImage,
      this.displayName,
      this.link});

How can I keep field name unmodified

When json has a name with underline, it will convert to hump name. Like

{
"product_id": 1
}

will generate

class Product {
  int productId;

product_id -> productId.
I think it's correspond to dart code style.

But how can I keep the name untouched if I want.

Case conversion failed

The first letter of the word that should have been all capitalized has become a lowercase letter.
Is this because of a grammatical limitation or an unresolved bug?

Please pay attention to the class Result and the Attributes NAME。

Thanks。

My Json:

{
    "flag": "T",
    "msg": "success",
    "err": "",
    "result": [
        {
            "NAME": "Angular"
        },
        {
            "NAME": "React"
        },
        {
            "NAME": "Vue"
        },
        {
            "NAME": "Webpack"
        }
    ]
}

Expected

generate:

class Autogenerated {
  String _flag;
  String _msg;
  String _err;
  List<Result> _result;

  Autogenerated({String flag, String msg, String err, List<Result> result}) {
    this._flag = flag;
    this._msg = msg;
    this._err = err;
    this._result = result;
  }

  String get flag => _flag;
  set flag(String flag) => _flag = flag;
  String get msg => _msg;
  set msg(String msg) => _msg = msg;
  String get err => _err;
  set err(String err) => _err = err;
  List<Result> get result => _result;
  set result(List<Result> result) => _result = result;

  Autogenerated.fromJson(Map<String, dynamic> json) {
    _flag = json['flag'];
    _msg = json['msg'];
    _err = json['err'];
    if (json['result'] != null) {
      _result = new List<Result>();
      json['result'].forEach((v) {
        _result.add(new Result.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['flag'] = this._flag;
    data['msg'] = this._msg;
    data['err'] = this._err;
    if (this._result != null) {
      data['result'] = this._result.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class Result {
  String _NAME;

  Result({String NAME}) {
    this._NAME = NAME;
  }

  String get NAME => _NAME;
  set NAME(String NAME) => _NAME = NAME;

  Result.fromJson(Map<String, dynamic> json) {
    _NAME = json['NAME'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['NAME'] = this._NAME;
    return data;
  }
}

NOW

generate:

class Autogenerated {
  String _flag;
  String _msg;
  String _err;
  List<Result> _result;

  Autogenerated({String flag, String msg, String err, List<Result> result}) {
    this._flag = flag;
    this._msg = msg;
    this._err = err;
    this._result = result;
  }

  String get flag => _flag;
  set flag(String flag) => _flag = flag;
  String get msg => _msg;
  set msg(String msg) => _msg = msg;
  String get err => _err;
  set err(String err) => _err = err;
  List<Result> get result => _result;
  set result(List<Result> result) => _result = result;

  Autogenerated.fromJson(Map<String, dynamic> json) {
    _flag = json['flag'];
    _msg = json['msg'];
    _err = json['err'];
    if (json['result'] != null) {
      _result = new List<Result>();
      json['result'].forEach((v) {
        _result.add(new Result.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['flag'] = this._flag;
    data['msg'] = this._msg;
    data['err'] = this._err;
    if (this._result != null) {
      data['result'] = this._result.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class Result {
  String _nAME;

  Result({String nAME}) {
    this._nAME = nAME;
  }

  String get nAME => _nAME;
  set nAME(String nAME) => _nAME = nAME;

  Result.fromJson(Map<String, dynamic> json) {
    _nAME = json['NAME'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['NAME'] = this._nAME;
    return data;
  }
}

A class is not generated

The JSON is as follows, Directors did not generate, resulting in the generated model class error

{
        "rating": {
            "max": 10,
            "average": 8.1,
            "stars": "40",
            "min": 0
        },
        "genres": [
            "动作",
            "科幻",
            "冒险"
        ],
        "title": "后天",
        "casts": [
            {
                "alt": "https://movie.douban.com/celebrity/1002679/",
                "avatars": {
                    "small": "https://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p52.webp",
                    "large": "https://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p52.webp",
                    "medium": "https://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p52.webp"
                },
                "name": "丹尼斯·奎德",
                "id": "1002679"
            },
            {
                "alt": "https://movie.douban.com/celebrity/1048002/",
                "avatars": {
                    "small": "https://img1.doubanio.com/view/celebrity/s_ratio_celebrity/public/p12737.webp",
                    "large": "https://img1.doubanio.com/view/celebrity/s_ratio_celebrity/public/p12737.webp",
                    "medium": "https://img1.doubanio.com/view/celebrity/s_ratio_celebrity/public/p12737.webp"
                },
                "name": "杰克·吉伦哈尔",
                "id": "1048002"
            },
            {
                "alt": "https://movie.douban.com/celebrity/1021998/",
                "avatars": {
                    "small": "https://img1.doubanio.com/view/celebrity/s_ratio_celebrity/public/p629.webp",
                    "large": "https://img1.doubanio.com/view/celebrity/s_ratio_celebrity/public/p629.webp",
                    "medium": "https://img1.doubanio.com/view/celebrity/s_ratio_celebrity/public/p629.webp"
                },
                "name": "埃米·罗森",
                "id": "1021998"
            }
        ],
        "collect_count": 326849,
        "original_title": "The Day After Tomorrow",
        "subtype": "movie",
        "directors": [
            {
                "alt": "https://movie.douban.com/celebrity/1048002/",
                "avatars": {
                    "small": "https://img1.doubanio.com/view/celebrity/s_ratio_celebrity/public/p12737.webp",
                    "large": "https://img1.doubanio.com/view/celebrity/s_ratio_celebrity/public/p12737.webp",
                    "medium": "https://img1.doubanio.com/view/celebrity/s_ratio_celebrity/public/p12737.webp"
                },
                "name": "杰克·吉伦哈尔",
                "id": "1048002"
            }
        ],
        "year": "2004",
        "images": {
            "medium": "https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2209602029.webp"
        },
        "alt": "https://movie.douban.com/subject/1308779/",
        "id": "1308779"
    }

Arrays of array is not supported

{ "code": 0, "data": { "statistic1": { "count": [ [ 2 ] ], "duration": [ [ 7200 ] ], "x": [ "经销商门店1" ], "y": [ "DREAM-6" ] }, "statistic2": { "count": [ 6 ], "duration": [ 21600 ], "x": [ "经销商门店1" ] }, "statistic3": { "count": [ 3 ], "duration": [ 10800 ], "x": [ "DREAM-6" ] }, "statistic4": { "count": [ 2 ], "duration": [ 7200 ], "x": [ "88888887" ] } }, "message": "" }

escaping variables

hi,

i have an api which responds me an json like this:
"timestamp":{"$date":1608937653515}

the $date is not escaped in the coding and results in a null

best regards
harald

option to generate final

It would be nice to have an option simliar to Use private fields to generate fields as final, along with marking the class as constwould be great to allow immutable by default data model classes.

Idea of copyWith and initial

When i am about to create a model, i write json to dart and use your repository, then add my copyWith and initial, lets say we have A model it contains

class A{
    String b;
    String c;
}

I generate your json to dart and add these

A copyWith({String b, String c}) {
    return A(
        b: b ?? this.b,
        c: c ?? this.c
        );
  }
factory A.initial(){
    return A(b:"", c:"");
}

I know that im asking this because of my lazyness but u can generate these for everyone(mostly me)

String is not a subtype of Null

Some of my json object has rating 5.5
Some of my json object has rating null

In some cases like this "json_to_dart" write Null Rating.
Where it should write dynamic Rating

Support other naming conventions

It would be nice if the project could support other naming conventions. Currently it only supports camelCase but it would be helpful to allow the user to choose snake_case just like the private fields option.

Provide hints to the generator to overwrite types

hi @javiercbk ,
Thanks for your awesome project, it is very helpful and saving much time when I want to generate json as dart class model.

But, sometime I found a weird json like this

[
    {
        "volume":123
    },
    {
        "volume":123.5
    },
    {
        "volume":null
    } 
]

it will be awesome if there is an option to cast all int and double as String in your project..
thank you

希望可以做成vscode扩展

希望可以做成vscode扩展
可以右键选中JSON, 输名类名称,一键生成代码.

I hope I can make a vscode extension.
You can right-click on JSON, enter the name of the class, and generate the code with one click.

Give Option to make Json Serializable

Greetings!

I have used this tool. It is very useful excepting some problems.

I am using json_serializable library for JSON Parsing. It is creating toJson and fromJson method itself, we just need to write their format.

Example :

import 'package:json_annotation/json_annotation.dart';

part 'example.g.dart';

@JsonSerializable(nullable: false)
class Person {
  final String firstName;
  final String lastName;
  final DateTime dateOfBirth;

  Person({this.firstName, this.lastName, this.dateOfBirth});

  factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);

  Map<String, dynamic> toJson() => _$PersonToJson(this);
}

Hope for best if you can also support this thing.

Only the first element in an array is scanned

Currently the library only checks for the first element of an array in order to extract the schema. Checking all elements in the array and completing missing fields would be an improvement.

It should also raise an error when the basic structure is broken among different array elements.

not work at

not work at:
{
"x": {
"q": [],
"t": [],
"e": [
{}
]
}
}

Unable to generate dart code for json having nested list.

Hi ,
I was trying to parse the below json, but due to nested list it was unable to parse the json.
After removing the nested list tool generates the code.
{
"streamedOn": "abcd",
"frameTime": 163,
"inference": [
[
56,
0.026197034865617752,
0.5304847955703735,
0.19273671507835388,
0.6165180206298828,
0.27010291814804077
],
[
56,
0.026197034865617752,
0.5304847955703735,
0.19273671507835388,
0.6165180206298828,
0.27010291814804077
]
],
"peopleCount": 0,
"frameUrl": "https://dummy_image/dummy_image.jpeg"
}

Caveats should be listed in the main page

Caveats should be posted in the main page to warn users about how to use this tool properly.
Along side with the caveats, there should be examples on common errors and how to solve them like null values, empty or null arrays.

Unable to parse json

{ "glossary": { "title": "example glossary", "GlossDiv": { "title": "S", "GlossList": { "GlossEntry": { "ID": "SGML", "SortAs": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Acronym": "SGML", "Abbrev": "ISO 8879:1986", "GlossDef": { "para": "A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": ["GML", "XML"] }, "GlossSee": "markup" } } } } }

copy this json and put it in box and it unable to parse it .

Dont parse correct json

Error: Cannot generate dart code. Please check the project caveats.

{
"SessionExpire": 240,
"StayLoggedInTime": 10000,
"StayLoggedInDeviceType": 3,
"CanShareAsNews": true,
"NewsFeedSummaryLength": 300,
"ApplicationLanguageAccess": [
1
],
"GAAccount": "UA-75836431-2",
"FileUploadLimit": 50,
"FileTypeExtensions": {
".XPM": 12,
".JP2": 12,
".HTML": 8
},
"CurrentVersion": {
"Id": 133,
"VersionMajor": 129,
"VersionMinor": 5,
"UpgradeOn": "2019-01-24T16:13:00+01:00",
"UpgradeEndTime": "2019-01-24T16:23:00+01:00",
"UpgradeVersionType": 1,
"InternalDescription": null,
"CustomerInformation": "Denna uppgradering innehåller buggfixar.",
"VersionNumberText": "0.0.129.5",
"UpgradeStatusType": 2,
"SecondsUntilUpgradeStart": -24180091,
"CreatedByUserId": 7904,
"CreatedOn": "2019-01-24T15:14:18+01:00",
"ChangedByUserId": 7904,
"ChangedOn": "2019-01-24T15:14:18+01:00",
"CreatedByUserName": "Mattias Andersson",
"ChangedByUserName": "Mattias Andersson"
},
"NumberOfDaysTillNextUpgrade": 2147483647,
"UserIPAddress": "78.159.99.208",
"Senders": [
"Chain SMS Sender"
],
"CurrentCulture": "en-US",
"UserApplicationLanguageType": 2,
"ShowStayLoggedIn": true,
"IsRequestAccessAvailable": true,
"SupportPhoneNumber": "+380666901413",
"SupportEmailAddress": "[email protected]",
"CustomerId": 25,
"CustomerName": "Chainformation",
"MobileAppName": "Development App",
"DefaultApplicationLanguageType": 2,
"AdConfigs": null,
"CustomButtons": [],
"CustomerSettings": {
"Id": 1,
"BrandingColor": "27ae60",
"LogoReference": {
"Id": 2377,
"ObjectId": 1,
"MediaBankFileId": 4552,
"ObjectType": 58,
"IsDirectUpload": false,
"PhysicalFileName": "98fe2958-5a34-4e75-be45-0f470b65ef41",
"Extension": ".jpg",
"Name": "images (1)",
"FileType": 1,
"Width": 300,
"Height": 168,
"CreatedOn": "2019-01-14T15:20:10+01:00",
"CreatedByUserId": 7904,
"CreatedByUserName": "Mattias Andersson",
"CreatedByMediaBankPhysicalFileName": "d6f1b7d4-3437-4544-8eb1-4876b3af0502",
"ContentType": "image/jpeg",
"ReferenceType": 2
},
"LandscapeReference": {
"Id": 2378,
"ObjectId": 1,
"MediaBankFileId": 4553,
"ObjectType": 58,
"IsDirectUpload": false,
"PhysicalFileName": "077114c6-1ef1-49ae-90e2-c01c1b5954fb",
"Extension": ".jpg",
"Name": "Bos_grunnien",
"FileType": 1,
"Width": 3264,
"Height": 2448,
"CreatedOn": "2019-01-14T15:20:18+01:00",
"CreatedByUserId": 7904,
"CreatedByUserName": "Mattias Andersson",
"CreatedByMediaBankPhysicalFileName": "d6f1b7d4-3437-4544-8eb1-4876b3af0502",
"ContentType": "image/jpeg",
"ReferenceType": 3
},
"PortraitReference": {
"Id": 2379,
"ObjectId": 1,
"MediaBankFileId": 4554,
"ObjectType": 58,
"IsDirectUpload": false,
"PhysicalFileName": "9bec8dd7-602c-4aa8-b0f6-00277e077604",
"Extension": ".jpg",
"Name": "165",
"FileType": 1,
"Width": 900,
"Height": 600,
"CreatedOn": "2019-01-14T15:20:30+01:00",
"CreatedByUserId": 7904,
"CreatedByUserName": "Mattias Andersson",
"CreatedByMediaBankPhysicalFileName": "d6f1b7d4-3437-4544-8eb1-4876b3af0502",
"ContentType": "image/jpeg",
"ReferenceType": 4
}
},
"UpcomingVersion": null,
"ChecklistPresenceEnabled": false,
"StorageDomain": "https://ccm2westeurope.blob.core.windows.net",
"ApplicationSettingAccessTypes": [
{
"ApplicationSettingType": 103,
"AccessRightTypes": [
40
]
},
{
"ApplicationSettingType": 104,
"AccessRightTypes": [
40
]
},
{
"ApplicationSettingType": 105,
"AccessRightTypes": [
10,
20,
30,
40
]
}
],
"ContentLanguages": [
{
"Id": 1,
"IsDefaultLanguage": false
},
{
"Id": 2,
"IsDefaultLanguage": true
},
{
"Id": 4,
"IsDefaultLanguage": false
},
{
"Id": 10,
"IsDefaultLanguage": false
}
]
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.