将JSON大文件转换为制表符分隔的平面文件

时间:2015-09-24 20:25:14

标签: java json api

我目前有供应商提供API json格式文件,需要将它们转换为平面文件,以便将其加载到SQL服务器中。下面是JSON文件中的一行(超过700K +行中的一行)。

我需要从C:\ Users \ Lumen \ Documents \ APIfiles_fromvendor \ test.json上的目录导入所有文件。

我正在学习的任何帮助都将受到赞赏。

以下是样本:

 {
   "vendornameoutput":[
      {
         "stores":{
            "offers":[
               {
                  "avgRating":0.0,
                  "userRatings":0,
                  "fulfilledBy":"",
                  "availability":"IN_STOCK",
                  "listPrice":128.88,
                  "maxRating":0,
                  "salePrice":128.88,
                  "upcs":[

                  ],
                  "imageUrl":"http://d2dddpb.JPG",
                  "shippingText":"This item ships free!",
                  "mpns":[
                     "723fdads32"
                  ],
                  "seller":"",
                  "cartPrice":false,
                  "addOnItem":false,
                  "productUrl":"http://www.zoyyyyr.com",
                  "salesRank":0,
                  "usedOffers":0,
                  "priceHistoryAvailable":true,
                  "lastRecordedAt":1441326319301,
                  "buyBoxWinner":false,
                  "newOffers":0,
                  "sku":"212120G319514518571",
                  "refurbishedOffers":0,
                  "additionalImageUrls":[

                  ]
               },
               {
                  "avgRating":0.0,
                  "userRatings":0,
                  "fulfilledBy":"",
                  "availability":"IN_STOCK",
                  "listPrice":128.88,
                  "maxRating":0,
                  "salePrice":128.88,
                  "upcs":[

                  ],
                  "imageUrl":"http://d2pbmlo3fAS01.JPG",
                  "shippingText":"This item ships free!",
                  "mpns":[
                     "72fsdfg5332"
                  ],
                  "seller":"",
                  "cartPrice":false,
                  "addOnItem":false,
                  "productUrl":"http://www.zddodadfaryyyo.com/i/G3198dfasa571/?category=9668",
                  "salesRank":0,
                  "usedOffers":0,
                  "priceHistoryAvailable":true,
                  "lastRecordedAt":1429844879892,
                  "buyBoxWinner":false,
                  "newOffers":0,
                  "sku":"ddadG3dasd198ddds571",
                  "refurbishedOffers":0,
                  "additionalImageUrls":[

                  ]
               }
            ],
            "storeId":2656,
            "storeName":"testsite",
            "title":"Pump Gun Only, For Use With 1ED22 Oiler"
         },
         "mpns":[
            "72ddd332"
         ],
         "imageUrl":"http://d2ulldddda/Z_HJFvfo5oy.JPG",
         "categoryName":"Hand Tools",
         "brandName":"Ridgid",
         "categoryIdPath":"10167 > 16031 > 16032",
         "categoryNamePath":"Tools & Home Improvement > Power & Hand Tools > Hand Tools",
         "brandId":19970,
         "title":"Pump Gun Only, For Use With 1EDffsad22 Oiler",
         "categoryId":16032,
         "upcs":[

         ],
         "currency":"USD",
         "mpid":"0fb1f23c94c3bc7928ee72f9880a2174",
         "countryCode":"US",
         "lastRecordedAt":1442922991002,
         "storesCount":6,
         "offersCount":10,
         "maxSalePrice":280.75,
         "minSalePrice":128.88
      }
   ]
}

1 个答案:

答案 0 :(得分:0)

您可以使用Jackson流媒体API(http://www.mkyong.com/java/jackson-streaming-api-to-read-and-write-json/)来浏览您的数据。

如果你真的需要通过flatfile(csv?)上传它,你可以使用像https://commons.apache.org/proper/commons-csv/这样的框架来传输输出。

Import CSV file into SQL Server提供了有关如何上传csv文件的更多详细信息。

我无法提供任何实施帮助,因为我不知道您在哪里需要帮助。想想你的问题,有什么解决方案,每个解决方案有什么缺点。选择最简单的一个。在子问题中分开并逐一解决它们。通过编写小代码示例证明他们可以工作。将这些集成到工作组件中并编写测试以证明每个解决方案都能正常工作。