• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

Parse JSON file using Java Scripts (In Informatica Power Center)

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am not a Java expert and hence struggling to parse the JSON file in Informatica Power Center using JTX.
I have the following JSON file <<I did not copy the entire file due to size>> and I have the following JS code in the JTX.
{
  "took":6,
  "timed_out":false,
  "_shards":{
     "total":5,
     "successful":5,
     "skipped":0,
     "failed":0
  },

  "hits":{
     "total":{
        "value":593,
        "relation":"eq"
     },

     "max_score":1,
     "hits":[
        {
           "_index":"store_data_1_product_1616054411",
           "_type":"_doc",
           "_id":"9",
           "_score":1,
           "_source":{
              "attribute_set_id":4,
              "created_at":"2020-07-03 19:59:38",
              "updated_at":"2021-03-06 18:57:19",
              "type_id":"simple",
              "sku":"VP000024",
              "id":9,
              "tsk":1616054411,
              "manufacturer":5476,
              "status":1,
              "visibility":4,
              "tax_class_id":2,
              "cannabis":1,
              "sexual_wellness":0,
              "pet_friendly":0,
              "name":"Rainmaker ",
              "image":"/c/l/cld_5f08a62f7416d_Chemistry-Rainmaker-VP000024-1.jpg",
              "small_image":"/c/l/cld_5f08a62f7416d_Chemistry-Rainmaker-VP000024-1.jpg",
              "thumbnail":"/c/l/cld_5f08a62f7416d_Chemistry-Rainmaker-VP000024-1.jpg",
              "image_label":"product-images/VP000024/Chemistry-Rainmaker-VP000024-1",
              "small_image_label":"product-images/VP000024/Chemistry-Rainmaker-VP000024-1",
              "thumbnail_label":"product-images/VP000024/Chemistry-Rainmaker-VP000024-1",
              "url_key":"vp000024",
              "msrp_display_actual_price_type":"0",
              "gift_message_available":false,
              "gift_wrapping_available":false,
              "is_returnable":true,
              "swatch_image":"/c/l/cld_5f08a62f7416d_Chemistry-Rainmaker-VP000024-1.jpg",
              "classification":"indica",
              "treez_uom":"grams",
              "price":30,
              "thc_percentage":78.2,
              "thc_mg_package":391,
              "cbd_percentage":0.3,
              "cbd_mg_package":2,
              "treez_amount":0.5,
              "description":"Chemistry brings small-batch craft cannabis to you in vape form, with a proprietary extraction process that aims to provide a vaping experience that is as close to the cured, dried cannabis flower as possible. This single-source, single-strain, whole-flower vape is extracted from cannabis sun-grown in Humboldt by Tina Gordon at Moon Made Farms. Today’s forecast? A deluge of sweet and skunky good vibes courtesy of Rainmaker. Wade into a mellow mood with this indica hybrid. Chemistry: Stay True to the Plant.",
              "treez_product_id":"a2c98fcd-2fbd-4a3a-a9bd-404348796bf8",
              "treez_category":"Cartridge",
              "treez_sub_category":"Pod",
              "path":"/brands/chemistry/rainmaker/",

When I debug, I get the error: "jsonobject cannot be cast to class org.json.simple.jsonarray"

here the InputFile is a input port containing the path of my JSON file.



Any help to fix and read/parse my JSON file is highly appreciated. I can provide more info if required. I am new to JSON and Java and needed a help.
 
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does the code do now, and how is that different from what it should do? Are there any exception or error messages? If so, post the full stack trace.
 
Tim Moores
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the future, please don't put so much empty white space in your code - it makes it very hard to read. Now that I removed all that, I see you're getting a ClassCastException - that must be in line 10. Which object are you casting to JSONArray? Look closely.
 
Manikandan Arunachalam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thank you!
I don't have any Java exposure and I am supposed to read the JSON file and convert them into csv format so that I can parse in Informatica Power Center.

I am mostly looking to read the elements from "hits", "category" and "stock".

{
  "took":6,
  "timed_out":false,
  "_shards":{
     "total":5,
     "successful":5,
     "skipped":0,
     "failed":0
  },
  "hits":{
     "total":{
        "value":593,
        "relation":"eq"
     },
     "max_score":1,
     "hits":[
        {
           "_index":"store_data_1_product_1616054411",
           "_type":"_doc",
           "_id":"9",
           "_score":1,
           "_source":{
              "attribute_set_id":4,
              "created_at":"2020-07-03 19:59:38",
              "updated_at":"2021-03-06 18:57:19",
              "type_id":"simple",
              "sku":"VP000024",
              "id":9,
              "tsk":1616054411,
              "manufacturer":5476,
              "status":1,
              "visibility":4,
              "tax_class_id":2,
              "cannabis":1,
              "sexual_wellness":0,
              "pet_friendly":0,
              "name":"Rainmaker ",
              "image":"/c/l/cld_5f08a62f7416d_Chemistry-Rainmaker-VP000024-1.jpg",
              "small_image":"/c/l/cld_5f08a62f7416d_Chemistry-Rainmaker-VP000024-1.jpg",
              "thumbnail":"/c/l/cld_5f08a62f7416d_Chemistry-Rainmaker-VP000024-1.jpg",
              "image_label":"product-images/VP000024/Chemistry-Rainmaker-VP000024-1",
              "small_image_label":"product-images/VP000024/Chemistry-Rainmaker-VP000024-1",
              "thumbnail_label":"product-images/VP000024/Chemistry-Rainmaker-VP000024-1",
              "url_key":"vp000024",
              "msrp_display_actual_price_type":"0",
              "gift_message_available":false,
              "gift_wrapping_available":false,
              "is_returnable":true,
              "swatch_image":"/c/l/cld_5f08a62f7416d_Chemistry-Rainmaker-VP000024-1.jpg",
              "classification":"indica",
              "treez_uom":"grams",
              "price":30,
              "thc_percentage":78.2,
              "thc_mg_package":391,
              "cbd_percentage":0.3,
              "cbd_mg_package":2,
              "treez_amount":0.5,
              "description":"Chemistry brings small-batch craft cannabis to you in vape form, with a proprietary extraction process that aims to provide a vaping experience that is as close to the cured, dried cannabis flower as possible. This single-source, single-strain, whole-flower vape is extracted from cannabis sun-grown in Humboldt by Tina Gordon at Moon Made Farms. Today’s forecast? A deluge of sweet and skunky good vibes courtesy of Rainmaker. Wade into a mellow mood with this indica hybrid. Chemistry: Stay True to the Plant.",
              "treez_product_id":"a2c98fcd-2fbd-4a3a-a9bd-404348796bf8",
              "treez_category":"Cartridge",
              "treez_sub_category":"Pod",
              "path":"/brands/chemistry/rainmaker/",
              "treez_product_ids":"{\"LAX1\":\"a2c98fcd-2fbd-4a3a-a9bd-404348796bf8\",\"SFO1\":\"6ebfa8f2-2f1b-4c0a-b583-09fbcd10c805\"}",
              "slug":"vp000024",
              "url_path":"vp000024.html",
              "category":[
                 {
                    "category_id":8,
                    "name":"Vape Pens",
                    "position":129
                 },
                 {
                    "category_id":9,
                    "name":"Cartridges",
                    "position":0
                 },
                 {
                    "category_id":35,
                    "name":"Shop All",
                    "position":572
                 }
              ],
              "category_ids":[
                 8,
                 9,
                 35
              ],
              "final_price":30,
              "regular_price":30,
              "media_gallery":[
                 {
                    "typ":"image",
                    "image":"/c/l/cld_5f08a62f7416d_Chemistry-Rainmaker-VP000024-1.jpg",
                    "lab":"product-images/VP000024/Chemistry-Rainmaker-VP000024-1",
                    "pos":1
                 },
                 {
                    "typ":"image",
                    "image":"/c/l/cld_5f08a63111440_Chemistry-Rainmaker-VP000024-2.jpg",
                    "lab":"product-images/VP000024/Chemistry-Rainmaker-VP000024-2",
                    "pos":2
                 },
                 {
                    "typ":"image",
                    "image":"/c/l/cld_5f08a63297299_Chemistry-Rainmaker-VP000024-3.jpg",
                    "lab":"product-images/VP000024/Chemistry-Rainmaker-VP000024-3",
                    "pos":3
                 },
                 {
                    "typ":"image",
                    "image":"/c/l/cld_5f08a63419f4e_Chemistry-Rainmaker-VP000024-4.jpg",
                    "lab":"product-images/VP000024/Chemistry-Rainmaker-VP000024-4",
                    "pos":4
                 }
              ],
              "product_links":[
                 
              ],
              "stock":{
                 "qty":0,
                 "is_in_stock":false,
                 "stock_status":0,
                 "min_qty":0,
                 "max_sale_qty":10000,
                 "product_id":9
              },
              "stocks":{
                 "default":{
                    "qty":1000,
                    "is_in_stock":true,
                    "stock_status":1,
                    "min_qty":0,
                    "max_sale_qty":10000,
                    "product_id":9
                 },
                 "LAX1":{
                    "qty":0,
                    "is_in_stock":false,
                    "stock_status":0,
                    "min_qty":0,
                    "max_sale_qty":10000,
                    "product_id":9
                 },
                 "SFO1":{
                    "qty":0,
                    "is_in_stock":false,
                    "stock_status":0,
                    "min_qty":0,
                    "max_sale_qty":10000,
                    "product_id":9
                 }
              },
              "configurable_children":[
                 
              ]
           }
        },
        {
           "_index":"store_data_1_product_1616054411",
           "_type":"_doc",
           "_id":"35",
           "_score":1,
           "_source":{
              "attribute_set_id":4,
              "created_at":"2020-07-03 19:59:40",
              "updated_at":"2021-03-16 23:27:17",
              "type_id":"simple",
              "sku":"FL000098",
              "id":35,
              "tsk":1616054411,
              "manufacturer":5486,
              "status":1,
              "visibility":4,
              "tax_class_id":2,
              "cannabis":1,
              "sexual_wellness":0,
              "pet_friendly":0,
              "name":"Jack",
               .......

Thanks,
Mani A
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic