How do I Create a Nested JSON Object in Groovy?

Поделиться
HTML-код
  • Опубликовано: 13 дек 2024

Комментарии • 8

  • @jlei6802
    @jlei6802 Месяц назад +1

    very informative and thank you

  • @jlei6802
    @jlei6802 Месяц назад +1

    Is there a way to control the casing of the parameter name? eg: FirstName instead of firstName? I've put variable name as FirstName but it still show up as firstName

    • @testingtooling
      @testingtooling  Месяц назад +1

      Yes, it is possible. Instead of using firstName variable in the class Person, you can use FirstName instead. In video ruclips.net/video/WGc5jI_unk0/видео.html, change line no 26

    • @testingtooling
      @testingtooling  Месяц назад

      If you face an issue, please reach out. Happy to hop on call

    • @jlei6802
      @jlei6802 Месяц назад

      @@testingtooling That what I thought too but doesn't seem to work as such. for some reason, it camelCase when using Class
      class Applicant {
      String FirstName
      String LastName
      String DatOfBirth
      public Applicant(String Fname, String Lname, String Dob){
      this.FirstName = Fname
      this.LastName = Lname
      this.DatOfBirth = Dob
      }
      }
      Applicant Sample = new Applicant("fName", "LName", "1976-08-11")
      def theJson = new JsonBuilder(Sample).toPrettyString()
      println(theJson);
      println(new JsonBuilder(FirstName:"name"))
      Output:
      {
      "datOfBirth": "1976-08-11",
      "firstName": "fName",
      "lastName": "LName"
      }
      {"FirstName":"name"}

  • @akramjavid785
    @akramjavid785 Год назад

    {
    "cargos": [{
    "kind": "a",
    "type": "b",
    "objects": [{
    "identifier": "xyz"
    }]
    },
    {
    "kind": "a",
    "type": "d",
    "objects": [{
    "_identifier": "xyz"
    }]
    }
    ]
    }