title: Writing class for different JSON files
body: <p>I have recently started my journey in Flutter(Dart). I am trying to build an application which fetches some JSON information using an API call.</p>
  <p>I have successfully written a code for the following JSON file</p>
  <pre><code>[
    {
      &quot;on_api&quot;: &quot;1&quot;,
      &quot;tl_api&quot;: &quot;10&quot;,
      &quot;pl1_api&quot;: &quot;Smoor Chocolates Lounge&quot;,
      &quot;pl2_api&quot;: &quot;Vasant Nagar&quot;,
      &quot;dl1_api&quot;: &quot;MySoftwareCompany Software Pvt. Ltd.&quot;,
      &quot;dl2_api&quot;: &quot;Cunningham Road, Bengaluru - 560052&quot;,
      &quot;fn_api&quot;: &quot;Snehanshu&quot;,
      &quot;ln_api&quot;: &quot;Bhattacharya&quot;,
      &quot;cn_api&quot;: &quot;0123456789&quot;,
      &quot;eid_api&quot;: &quot;snehanshu@anyemailexample.com&quot;
    },
    {
      &quot;on_api&quot;: &quot;1&quot;,
      &quot;tl_api&quot;: &quot;10&quot;,
      &quot;pl1_api&quot;: &quot;Smoor Chocolates Lounge&quot;,
      &quot;pl2_api&quot;: &quot;Vasant Nagar&quot;,
      &quot;dl1_api&quot;: &quot;MySoftwareCompany Software Pvt. Ltd.&quot;,
      &quot;dl2_api&quot;: &quot;Cunningham Road, Bengaluru - 560052&quot;,
      &quot;fn_api&quot;: &quot;Snehanshu&quot;,
      &quot;ln_api&quot;: &quot;Bhattacharya&quot;,
      &quot;cn_api&quot;: &quot;0123456789&quot;,
      &quot;eid_api&quot;: &quot;snehanshu@anyemailexample.com&quot;
    },
    {
      &quot;on_api&quot;: &quot;1&quot;,
      &quot;tl_api&quot;: &quot;10&quot;,
      &quot;pl1_api&quot;: &quot;Smoor Chocolates Lounge&quot;,
      &quot;pl2_api&quot;: &quot;Vasant Nagar&quot;,
      &quot;dl1_api&quot;: &quot;MySoftwareCompany Software Pvt. Ltd.&quot;,
      &quot;dl2_api&quot;: &quot;Cunningham Road, Bengaluru - 560052&quot;,
      &quot;fn_api&quot;: &quot;Snehanshu&quot;,
      &quot;ln_api&quot;: &quot;Bhattacharya&quot;,
      &quot;cn_api&quot;: &quot;0123456789&quot;,
      &quot;eid_api&quot;: &quot;snehanshu@anyemailexample.com&quot;
    },
    {
      &quot;on_api&quot;: &quot;1&quot;,
      &quot;tl_api&quot;: &quot;10&quot;,
      &quot;pl1_api&quot;: &quot;Smoor Chocolates Lounge&quot;,
      &quot;pl2_api&quot;: &quot;Vasant Nagar&quot;,
      &quot;dl1_api&quot;: &quot;MySoftwareCompany Software Pvt. Ltd.&quot;,
      &quot;dl2_api&quot;: &quot;Cunningham Road, Bengaluru - 560052&quot;,
      &quot;fn_api&quot;: &quot;Snehanshu&quot;,
      &quot;ln_api&quot;: &quot;Bhattacharya&quot;,
      &quot;cn_api&quot;: &quot;0123456789&quot;,
      &quot;eid_api&quot;: &quot;snehanshu@anyemailexample.com&quot;
    },
    {
      &quot;on_api&quot;: &quot;1&quot;,
      &quot;tl_api&quot;: &quot;10&quot;,
      &quot;pl1_api&quot;: &quot;Smoor Chocolates Lounge&quot;,
      &quot;pl2_api&quot;: &quot;Vasant Nagar&quot;,
      &quot;dl1_api&quot;: &quot;MySoftwareCompany Software Pvt. Ltd.&quot;,
      &quot;dl2_api&quot;: &quot;Cunningham Road, Bengaluru - 560052&quot;,
      &quot;fn_api&quot;: &quot;Snehanshu&quot;,
      &quot;ln_api&quot;: &quot;Bhattacharya&quot;,
      &quot;cn_api&quot;: &quot;0123456789&quot;,
      &quot;eid_api&quot;: &quot;snehanshu@anyemailexample.com&quot;
    }
  ]
  </code></pre>
  <p>Here is its element class</p>
  <pre><code>class Element {
    Element({
      this.onApi,
      this.tlApi,
      this.pl1Api,
      this.pl2Api,
      this.dl1Api,
      this.dl2Api,
      this.fnApi,
      this.lnApi,
      this.cnApi,
      this.eidApi,
    });
  
    String onApi;
    String tlApi;
    String pl1Api;
    String pl2Api;
    String dl1Api;
    String dl2Api;
    String fnApi;
    String lnApi;
    String cnApi;
    String eidApi;
  
    factory Element.fromJson(Map&lt;String, dynamic&gt; json) =&gt; Element(
      onApi: json[&quot;order_number&quot;],
      tlApi: json[&quot;tl_api&quot;],
      pl1Api: json[&quot;pl1_api&quot;],
      pl2Api: json[&quot;pl2_api&quot;],
      dl1Api: json[&quot;dl1_api&quot;],
      dl2Api: json[&quot;dl2_api&quot;],
      fnApi: json[&quot;fn_api&quot;],
      lnApi: json[&quot;ln_api&quot;],
      cnApi: json[&quot;cn_api&quot;],
      eidApi: json[&quot;eid_api&quot;],
    );
  }
  </code></pre>
  <p>Here is its api calling code</p>
  <pre><code>import 'dart:convert';
  import 'package:http/http.dart';
  import 'package:smoorapplication/src/constants/constants.dart';
  import 'package:smoorapplication/src/model/elements.dart';
  
  Future&lt;List&lt;Element&gt;&gt; apiGetOrder() async{
    var response = await get(Uri.parse(MOCK_API_SMOOR_1));
    var jsonData = jsonDecode(response.body);
    List&lt;Element&gt; elements = &lt;Element&gt;[];
    for(var i in jsonData){
      Element element = Element.fromJson(i);
      elements.add(element);
    }
    print(elements.length);
  }
  </code></pre>
  <p>I want the api call code and element class code for this kind of messy JSON file</p>
  <pre><code>{
    &quot;orders&quot;: [
      {
        &quot;id&quot;: 3927180738697,
        &quot;admin_graphql_api_id&quot;: &quot;gid://shopify/Order/00000&quot;,
        &quot;app_id&quot;: 580111,
        &quot;browser_ip&quot;: &quot;122.172.179.207&quot;,
        &quot;buyer_accepts_marketing&quot;: false,
        &quot;cancel_reason&quot;: null,
        &quot;cancelled_at&quot;: null,
        &quot;cart_token&quot;: null,
        &quot;checkout_id&quot;: 20726986440841,
        &quot;checkout_token&quot;: &quot;65651fdv561165&quot;,
        &quot;client_details&quot;: {
          &quot;accept_language&quot;: &quot;en-US,en;q=0.9&quot;,
          &quot;browser_height&quot;: 860,
          &quot;browser_ip&quot;: &quot;122.172.179.207&quot;,
          &quot;browser_width&quot;: 1487,
          &quot;session_hash&quot;: null,
        },
        &quot;closed_at&quot;: null,
        &quot;confirmed&quot;: true,
        &quot;contact_email&quot;: null,
        &quot;created_at&quot;: &quot;2021-12-16T11:03:59+05:30&quot;,
        &quot;currency&quot;: &quot;INR&quot;,
        &quot;current_subtotal_price&quot;: &quot;500.00&quot;,
        &quot;current_subtotal_price_set&quot;: {
          &quot;shop_money&quot;: {
            &quot;amount&quot;: &quot;500.00&quot;,
            &quot;currency_code&quot;: &quot;INR&quot;
          },
          &quot;presentment_money&quot;: {
            &quot;amount&quot;: &quot;500.00&quot;,
            &quot;currency_code&quot;: &quot;INR&quot;
          }
        },
        &quot;current_total_discounts&quot;: &quot;0.00&quot;,
        &quot;current_total_discounts_set&quot;: {
          &quot;shop_money&quot;: {
            &quot;amount&quot;: &quot;0.00&quot;,
            &quot;currency_code&quot;: &quot;INR&quot;
          },
          &quot;presentment_money&quot;: {
            &quot;amount&quot;: &quot;0.00&quot;,
            &quot;currency_code&quot;: &quot;INR&quot;
          }
        },
        &quot;current_total_duties_set&quot;: null,
        &quot;current_total_price&quot;: &quot;600.00&quot;,
        &quot;current_total_price_set&quot;: {
          &quot;shop_money&quot;: {
            &quot;amount&quot;: &quot;600.00&quot;,
            &quot;currency_code&quot;: &quot;INR&quot;
          },
          &quot;presentment_money&quot;: {
            &quot;amount&quot;: &quot;600.00&quot;,
            &quot;currency_code&quot;: &quot;INR&quot;
          }
        },
        &quot;current_total_tax&quot;: &quot;91.52&quot;,
        &quot;current_total_tax_set&quot;: {
          &quot;shop_money&quot;: {
            &quot;amount&quot;: &quot;91.52&quot;,
            &quot;currency_code&quot;: &quot;INR&quot;
          },
          &quot;presentment_money&quot;: {
            &quot;amount&quot;: &quot;91.52&quot;,
            &quot;currency_code&quot;: &quot;INR&quot;
          }
        }
      }
    ]
  }
  
  </code></pre>