Description

An Attribute can be hidden (not generated) within Flat or Nested JSON output when its generated value is NULL or Blank (Empty). This can be done by selecting an output condition within the Attribute Dashboard for the Attribute. 


Note: Attributes can also be hidden (not included in the generated output) based on a condition. A great condition-based example can be viewed here. 


In This Article


Story

A tester wants an address2 Attribute to be hidden from the generated JSON output if it has a NULL or Blank (Empty) value. 


Note: This example is for generating Flat JSON with the JSONFileReceiver; however, it also applies when generating Nested JSON using the JSONSegmentMergeReceiver.


Project Setup

A Project has been set up with the default Project Version and a User Domain. The User Domain contains two address Attributes: 

  • address1 - street address
  • address2 - apartment or suite information



A JSONFileReceiver has been assigned to the User Domain, and the loopCount has been set to"10". A Scenario has also been added to the Domain.


address2 Attribute

This can be accomplished in many ways. For example, all values can be added to a ListGen Generator, which can generate a list of entered values, or a ListCSVGen Generator can be used to generate a list of values from a CSV file. 


For this example, we are using Linked Generators. This allows us to generate the required values and then use a MultiWeightGen Generator to control how often they are generated based on percentages. The following types of values will be generated: 

  • Apt or Suite
  • NULL
  • BLANK (EMPTY)




gen1 - ListGen Generator

The ListGen Generator is used to generate an Apt or Suite value. 



gen2 - NullGen Generator

The NullGen Generator generates a "NULL" value. 



gen3 - ConstantGen Generator

The ConstantGen Generator generates a BLANK (EMPTY) value. 



gen4 - MultiWeightGen Generator

The MultiWeightGen Generator determines how often each value type is generated within the output file. Values will be generated as follows: 

  • gen1 (ListGen)- 60%
  • gen2 (NullGen) - 15%
  • gen3 (ConstantGen) - 25%


Sample Output

This example will create a Flat JSON file with multiple records. If a record has a NULL or Blank value for the address2 Attribute, the address2 Attribute will not be included in the output for that record. 


  [
    {
      "id" : "1",
      "firstName" : "Breckenridge",
      "lastName" : "Somerville",
      "address1" : "1000 N Washington Dr",
      "city" : "Henderson",
      "state" : "Nevada",
      "zipCode" : "89002"
    },
    {
      "id" : "2",
      "firstName" : "Agee",
      "lastName" : "Snavely",
      "address1" : "1001 S Adams Sq",
      "address2" : "Apt B",
      "city" : "Deming",
      "state" : "New Mexico",
      "zipCode" : "88030"
    },
    {
      "id" : "3",
      "firstName" : "Seng",
      "lastName" : "Carnevale",
      "address1" : "1002 E Jefferson Ct",
      "address2" : "Suite A",
      "city" : "Tacoma",
      "state" : "Washington",
      "zipCode" : "98402"
    },
    {
      "id" : "4",
      "firstName" : "Kuehl",
      "lastName" : "Brough",
      "address1" : "1003 W Madison St",
      "city" : "Wilmington",
      "state" : "Delaware",
      "zipCode" : "19801"
    },
    {
      "id" : "5",
      "firstName" : "Sands",
      "lastName" : "Vieira",
      "address1" : "1004 NS Monroe Rd",
      "city" : "Concord",
      "state" : "North Carolina",
      "zipCode" : "28025"
    },
    {
      "id" : "6",
      "firstName" : "Oliver",
      "lastName" : "Studer",
      "address1" : "1005 NE Adams Ave",
      "city" : "Los Alamos",
      "state" : "New Mexico",
      "zipCode" : "87544"
    },
    {
      "id" : "7",
      "firstName" : "Crews",
      "lastName" : "Paris",
      "address1" : "1006 NW Jackson Blvd",
      "city" : "Athena",
      "state" : "Oregon",
      "zipCode" : "97813"
    },
    {
      "id" : "8",
      "firstName" : "Cunha",
      "lastName" : "Ignacio",
      "address1" : "1007 SE Van Buren Wy",
      "address2" : "Suite B",
      "city" : "Lime Springs",
      "state" : "Iowa",
      "zipCode" : "52155"
    },
    {
      "id" : "9",
      "firstName" : "Waldner",
      "lastName" : "Waggoner",
      "address1" : "1008 SW Harrison Ln",
      "address2" : "Apt A",
      "city" : "Reading",
      "state" : "Pennsylvania",
      "zipCode" : "19601"
    },
    {
      "id" : "10",
      "firstName" : "Huizar",
      "lastName" : "Hollifield",
      "address1" : "1009 EW Tyler Cir",
      "address2" : "Apt B",
      "city" : "Granger",
      "state" : "Indiana",
      "zipCode" : "46530"
    }
  ]