Customer Portal

How to use Json Extractor when records don't have all the same attributes

Comments 3

  • Avatar
    Lukas Cholasta
    0
    Comment actions Permalink
    Hi,

    I'm afraid that I don't fully understand what you want to achieve. I understand that the JSON files may have different structure. If the files contain some arrays that may have different number of fields, the solution will be quite easy. You just need to set the corresponding metadata container type to list and map it as an usual element (in the JSONExtract mapping property). For more detailed information see our blog, please.

    If the files have different count and names of elements, they cannot be parsed by a single JSONExtract. You will need to use multiple JSONExtract components, one for each file structure. You need to create a deciding structure capable of sending the file to the correct JSONExtract. You can do this by:



    If you want me to create a sample graph for you, send me the following, please.

      1. Some example input JSON files (2 or 3), so I can see what exactly is different.
      2. Your graph with its externalized dependencies (metadata, etc.), so I can see how you proceeded. Feel free to remove any sensitive information.
      3. The edited *.xsd file (with 115 rows), so I can see what went wrong.


    Best regards,
  • Avatar
    mcomsto
    0
    Comment actions Permalink
    I have similar issue, I think.

    Here is my sample data.

    {
    "total_results_count": 2,
    "code": "OK",
    "offset": 0,
    "results_count": 2,
    "results": [
    {
    "sem3_id": "2IFH5VS98y0gG22kIQi0i2",
    "name": "Sea Gull Lighting 8753-34 Single-Light Outdoor Wall Lantern with Smooth White Globe, Black",
    "model": "8753 34",
    "brand": "Sea Gull Lighting",
    "category": "Porch & Patio Lights",
    "color": "Smooth White",
    "created_at": 1347510294,
    "ean": "0785652875335",
    "features": {
    "Recommended Light Bulb Shape": "A19",
    "Number of Bulbs Required": "1",
    "Bulbs Included": "No",
    "Manufacturer Color/Finish": "Black",
    "Style": "Casual/Transitional",
    "Weather Resistant/Weatherproof": "Weatherproof",
    "Glass Color": "White",
    "Damp Rated": "Yes",
    "Hardware Included": "Yes",
    "Glass Style": "Flat",
    "Material": "Polycarbonate",
    "Dark Sky": "No",
    "Package Quantity": "1",
    "Bulb Type": "Incandescent",
    "Fixture Height (Inches)": "7.25",
    "Light Bulb Base Type": "Medium base (E-26)",
    "UL Safety Listing": "Yes",
    "Collection Name": "N/A",
    "ENERGY STAR Qualified": "No",
    "Maximum Bulb Wattage": "60",
    "Color/Finish Family": "Black",
    "CSA Safety Listing": "Yes",
    "Fixture Width (Inches)": "6",
    "Power Source": "Hardwired",
    "Motion Activated": "No",
    "Fixture Depth (Inches)": "7",
    "Size Classification": "Small (width of product 6-in below)",
    "ETL Safety Listing": "No"
    },
    "gtins": [
    "00785652875335"
    ],
    "geo": [
    "usa"
    ],
    "height": "184.15",
    "images_total": 0,
    "length": "177.80",
    "manufacturer": "Sea Gull Lighting",
    "mpn": "8753-34",
    "upc": "785652875335",
    "updated_at": 1466435233,
    "width": "152.40"
    },
    {
    "sem3_id": "0HukkZv3LTEGuMg6UQSaGY",
    "name": "Sea Gull Lighting 8753-34 One Light Outdoor Wall Fixture - Black Finish",
    "brand": "Sea Gull Lighting",
    "category": "Outdoor Lighting",
    "created_at": 1407272933,
    "features": {
    "Origin of Components": "USA and/or Imported",
    "Shipping Weight (in pounds)": "2.18"
    },
    "geo": [
    "usa"
    ],
    "images_total": 0,
    "manufacturer": "Sea Gull Lighting",
    "updated_at": 1464091362
    }
    ]
    }

    He is my jsonExtractor source mapping. In Bold, is the mapping I manually created, since I could not get the visual mapper to recognize the "features" data. I am trying to transform the features into a set of name/value pairs.

    For example,

    name:"Recommended Light Bulb Shape"/value:A19

    Is this possible?

    <Mappings>
    <Mapping element="json_object">
    <Mapping element="results" implicit="false" outPort="0"
    xmlFields="{}brand;{}category;{}color;{}created_at;{}ean;{}geo;{}gtins;{}height;{}images_total;{}length;{}manufacturer;{}model;{}mpn;{}name;{}sem3_id;{}upc;{}updated_at;{}width"
    cloverFields="brand;category;color;created_at;ean;geo;gtins;height;images_total;length;manufacturer;model;mpn;name;sem3_id;upc;updated_at;width">
    <Mapping element="features" outPort="3" parentKey="sem3_id" generatedKey="sem3_id"
    xmlFields="."
    cloverFields="featuresValue">
    </Mapping>

    <Mapping element="gtins" implicit="false" outPort="2" parentKey="sem3_id" generatedKey="sem3_id"
    xmlFields="."
    cloverFields="gtinsValue">
    </Mapping>
    <Mapping element="geo" outPort="1" parentKey="sem3_id" generatedKey="sem3_id"
    xmlFields="."
    cloverFields="geoValue">
    </Mapping>
    </Mapping>
    </Mapping>
    </Mappings>
  • Avatar
    Lukas Cholasta
    0
    Comment actions Permalink
    Hi mcomsto,

    You can parse the 'features' by a component called Normalizer and dynamic field access CTL functions. I attached a simple example graph which utilizes this approach.

    You mentioned that you cannot see the 'features' in the visual mapper of the JSONExtract component. I just copied your sample data into a file (with no editing) and was able to map them (see them in the mapping editor). I don't know what version of CloverETL you are using but you can try the newest one (4.2.0). You should be able to map everything via the mapping editor there.

    Also, the example graph should be viewed in the 4.2.0 Designer as it was created in that version. It uses sample data from your post.

    json_read.grf
    Best regards,

Please sign in to leave a comment.