Getting error while inserting array of json to bigQuery





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0
















Error while reading data, error message: Failed to parse JSON: No object found when new array is started.; BeginArray returned false




I have created below sample json data. which is array of json. And each json object is in new line.



It works, when I load only one json object without keeping inside array.



JSON body -



[
{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" },
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" },
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }
]









share|improve this question

























  • Can you explain how you do the insert command and provide an example

    – Tamir Klein
    Jan 3 at 11:17











  • I have uploaded this data in a file say -mydata.json in GCS bucket. Then from the google console webUI, I am creating table keeping schema auto-detect true. and uploading this file from GCS.

    – jyoti
    Jan 3 at 11:25








  • 1





    If you want the get 3 lines in BigQuery you can remove the from your JSON and it should work

    – Tamir Klein
    Jan 3 at 11:27











  • I did tried that. It dint work

    – jyoti
    Jan 4 at 8:56


















0
















Error while reading data, error message: Failed to parse JSON: No object found when new array is started.; BeginArray returned false




I have created below sample json data. which is array of json. And each json object is in new line.



It works, when I load only one json object without keeping inside array.



JSON body -



[
{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" },
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" },
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }
]









share|improve this question

























  • Can you explain how you do the insert command and provide an example

    – Tamir Klein
    Jan 3 at 11:17











  • I have uploaded this data in a file say -mydata.json in GCS bucket. Then from the google console webUI, I am creating table keeping schema auto-detect true. and uploading this file from GCS.

    – jyoti
    Jan 3 at 11:25








  • 1





    If you want the get 3 lines in BigQuery you can remove the from your JSON and it should work

    – Tamir Klein
    Jan 3 at 11:27











  • I did tried that. It dint work

    – jyoti
    Jan 4 at 8:56














0












0








0









Error while reading data, error message: Failed to parse JSON: No object found when new array is started.; BeginArray returned false




I have created below sample json data. which is array of json. And each json object is in new line.



It works, when I load only one json object without keeping inside array.



JSON body -



[
{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" },
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" },
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }
]









share|improve this question

















Error while reading data, error message: Failed to parse JSON: No object found when new array is started.; BeginArray returned false




I have created below sample json data. which is array of json. And each json object is in new line.



It works, when I load only one json object without keeping inside array.



JSON body -



[
{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" },
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" },
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }
]






google-bigquery






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 12:53









Tamir Klein

1,39111120




1,39111120










asked Jan 3 at 10:51









jyotijyoti

166




166













  • Can you explain how you do the insert command and provide an example

    – Tamir Klein
    Jan 3 at 11:17











  • I have uploaded this data in a file say -mydata.json in GCS bucket. Then from the google console webUI, I am creating table keeping schema auto-detect true. and uploading this file from GCS.

    – jyoti
    Jan 3 at 11:25








  • 1





    If you want the get 3 lines in BigQuery you can remove the from your JSON and it should work

    – Tamir Klein
    Jan 3 at 11:27











  • I did tried that. It dint work

    – jyoti
    Jan 4 at 8:56



















  • Can you explain how you do the insert command and provide an example

    – Tamir Klein
    Jan 3 at 11:17











  • I have uploaded this data in a file say -mydata.json in GCS bucket. Then from the google console webUI, I am creating table keeping schema auto-detect true. and uploading this file from GCS.

    – jyoti
    Jan 3 at 11:25








  • 1





    If you want the get 3 lines in BigQuery you can remove the from your JSON and it should work

    – Tamir Klein
    Jan 3 at 11:27











  • I did tried that. It dint work

    – jyoti
    Jan 4 at 8:56

















Can you explain how you do the insert command and provide an example

– Tamir Klein
Jan 3 at 11:17





Can you explain how you do the insert command and provide an example

– Tamir Klein
Jan 3 at 11:17













I have uploaded this data in a file say -mydata.json in GCS bucket. Then from the google console webUI, I am creating table keeping schema auto-detect true. and uploading this file from GCS.

– jyoti
Jan 3 at 11:25







I have uploaded this data in a file say -mydata.json in GCS bucket. Then from the google console webUI, I am creating table keeping schema auto-detect true. and uploading this file from GCS.

– jyoti
Jan 3 at 11:25






1




1





If you want the get 3 lines in BigQuery you can remove the from your JSON and it should work

– Tamir Klein
Jan 3 at 11:27





If you want the get 3 lines in BigQuery you can remove the from your JSON and it should work

– Tamir Klein
Jan 3 at 11:27













I did tried that. It dint work

– jyoti
Jan 4 at 8:56





I did tried that. It dint work

– jyoti
Jan 4 at 8:56












1 Answer
1






active

oldest

votes


















1














As explained in the documentation for loading JSON data stored in GCS to BigQuery, the JSON data must be in Newline Delimited JSON format, in which each line is a valid independent JSON value, therefore instead of (1), you should use (2)):



(1)



[
{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" },
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" },
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }
]


(2)



{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" }
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" }
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }




UPDATE:



Here a step-by-step guide in order to show how this works:



Create a JSON file (file.json in my case) with the content I shared (make sure to remove the array brackets and also the commas , at the end of each line:



$ cat file.json
{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" }
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" }
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }


Load the file to BQ, running a command like below:



$ bq load --autodetect --source_format=NEWLINE_DELIMITED_JSON dataset.table file.json                                   
Upload complete.
Waiting on bqjob_XXXXXXXXXXX ... (1s) Current status: DONE


Now query the table in order to check that the content was uploaded correctly:



$ bq query --use_legacy_sql=false "SELECT * FROM dataset.table"
Waiting on bqjob_r3ef14ac0d0a6c856_000001681819e9fc_1 ... (0s) Current status: DONE
+----------+-------+---------------------+---------------+----------------+--------------+---------------+-------------+-----------+
| sellerId | price | create_time | marktet_place | brand | country_code | category_name | gtin | item_name |
+----------+-------+---------------------+---------------+----------------+--------------+---------------+-------------+-----------+
| 234 | 2239 | 2017-07-19 16:00:46 | india | Om-Publication | IN | books | 123456 | dfkhjf |
| 234 | 2239 | 2017-08-19 16:00:46 | flipMe | Toy | IN | toy | 1234234445 | toy-gun |
| 234 | 2239 | 2017-09-19 16:00:46 | drone-maker | Drone-XX | IN | drone | 12342356456 | Drone |
+----------+-------+---------------------+---------------+----------------+--------------+---------------+-------------+-----------+





share|improve this answer


























  • @jyoti I have updated my answer, showing the step-by-step process to make the load work. If you still encounter issues with this, please be as specific as possible with the issues / errors that you are seeing.

    – dsesto
    Jan 4 at 9:26











  • Thanks. It works fine.

    – jyoti
    Jan 4 at 10:36












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020867%2fgetting-error-while-inserting-array-of-json-to-bigquery%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














As explained in the documentation for loading JSON data stored in GCS to BigQuery, the JSON data must be in Newline Delimited JSON format, in which each line is a valid independent JSON value, therefore instead of (1), you should use (2)):



(1)



[
{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" },
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" },
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }
]


(2)



{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" }
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" }
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }




UPDATE:



Here a step-by-step guide in order to show how this works:



Create a JSON file (file.json in my case) with the content I shared (make sure to remove the array brackets and also the commas , at the end of each line:



$ cat file.json
{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" }
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" }
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }


Load the file to BQ, running a command like below:



$ bq load --autodetect --source_format=NEWLINE_DELIMITED_JSON dataset.table file.json                                   
Upload complete.
Waiting on bqjob_XXXXXXXXXXX ... (1s) Current status: DONE


Now query the table in order to check that the content was uploaded correctly:



$ bq query --use_legacy_sql=false "SELECT * FROM dataset.table"
Waiting on bqjob_r3ef14ac0d0a6c856_000001681819e9fc_1 ... (0s) Current status: DONE
+----------+-------+---------------------+---------------+----------------+--------------+---------------+-------------+-----------+
| sellerId | price | create_time | marktet_place | brand | country_code | category_name | gtin | item_name |
+----------+-------+---------------------+---------------+----------------+--------------+---------------+-------------+-----------+
| 234 | 2239 | 2017-07-19 16:00:46 | india | Om-Publication | IN | books | 123456 | dfkhjf |
| 234 | 2239 | 2017-08-19 16:00:46 | flipMe | Toy | IN | toy | 1234234445 | toy-gun |
| 234 | 2239 | 2017-09-19 16:00:46 | drone-maker | Drone-XX | IN | drone | 12342356456 | Drone |
+----------+-------+---------------------+---------------+----------------+--------------+---------------+-------------+-----------+





share|improve this answer


























  • @jyoti I have updated my answer, showing the step-by-step process to make the load work. If you still encounter issues with this, please be as specific as possible with the issues / errors that you are seeing.

    – dsesto
    Jan 4 at 9:26











  • Thanks. It works fine.

    – jyoti
    Jan 4 at 10:36
















1














As explained in the documentation for loading JSON data stored in GCS to BigQuery, the JSON data must be in Newline Delimited JSON format, in which each line is a valid independent JSON value, therefore instead of (1), you should use (2)):



(1)



[
{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" },
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" },
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }
]


(2)



{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" }
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" }
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }




UPDATE:



Here a step-by-step guide in order to show how this works:



Create a JSON file (file.json in my case) with the content I shared (make sure to remove the array brackets and also the commas , at the end of each line:



$ cat file.json
{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" }
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" }
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }


Load the file to BQ, running a command like below:



$ bq load --autodetect --source_format=NEWLINE_DELIMITED_JSON dataset.table file.json                                   
Upload complete.
Waiting on bqjob_XXXXXXXXXXX ... (1s) Current status: DONE


Now query the table in order to check that the content was uploaded correctly:



$ bq query --use_legacy_sql=false "SELECT * FROM dataset.table"
Waiting on bqjob_r3ef14ac0d0a6c856_000001681819e9fc_1 ... (0s) Current status: DONE
+----------+-------+---------------------+---------------+----------------+--------------+---------------+-------------+-----------+
| sellerId | price | create_time | marktet_place | brand | country_code | category_name | gtin | item_name |
+----------+-------+---------------------+---------------+----------------+--------------+---------------+-------------+-----------+
| 234 | 2239 | 2017-07-19 16:00:46 | india | Om-Publication | IN | books | 123456 | dfkhjf |
| 234 | 2239 | 2017-08-19 16:00:46 | flipMe | Toy | IN | toy | 1234234445 | toy-gun |
| 234 | 2239 | 2017-09-19 16:00:46 | drone-maker | Drone-XX | IN | drone | 12342356456 | Drone |
+----------+-------+---------------------+---------------+----------------+--------------+---------------+-------------+-----------+





share|improve this answer


























  • @jyoti I have updated my answer, showing the step-by-step process to make the load work. If you still encounter issues with this, please be as specific as possible with the issues / errors that you are seeing.

    – dsesto
    Jan 4 at 9:26











  • Thanks. It works fine.

    – jyoti
    Jan 4 at 10:36














1












1








1







As explained in the documentation for loading JSON data stored in GCS to BigQuery, the JSON data must be in Newline Delimited JSON format, in which each line is a valid independent JSON value, therefore instead of (1), you should use (2)):



(1)



[
{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" },
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" },
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }
]


(2)



{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" }
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" }
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }




UPDATE:



Here a step-by-step guide in order to show how this works:



Create a JSON file (file.json in my case) with the content I shared (make sure to remove the array brackets and also the commas , at the end of each line:



$ cat file.json
{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" }
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" }
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }


Load the file to BQ, running a command like below:



$ bq load --autodetect --source_format=NEWLINE_DELIMITED_JSON dataset.table file.json                                   
Upload complete.
Waiting on bqjob_XXXXXXXXXXX ... (1s) Current status: DONE


Now query the table in order to check that the content was uploaded correctly:



$ bq query --use_legacy_sql=false "SELECT * FROM dataset.table"
Waiting on bqjob_r3ef14ac0d0a6c856_000001681819e9fc_1 ... (0s) Current status: DONE
+----------+-------+---------------------+---------------+----------------+--------------+---------------+-------------+-----------+
| sellerId | price | create_time | marktet_place | brand | country_code | category_name | gtin | item_name |
+----------+-------+---------------------+---------------+----------------+--------------+---------------+-------------+-----------+
| 234 | 2239 | 2017-07-19 16:00:46 | india | Om-Publication | IN | books | 123456 | dfkhjf |
| 234 | 2239 | 2017-08-19 16:00:46 | flipMe | Toy | IN | toy | 1234234445 | toy-gun |
| 234 | 2239 | 2017-09-19 16:00:46 | drone-maker | Drone-XX | IN | drone | 12342356456 | Drone |
+----------+-------+---------------------+---------------+----------------+--------------+---------------+-------------+-----------+





share|improve this answer















As explained in the documentation for loading JSON data stored in GCS to BigQuery, the JSON data must be in Newline Delimited JSON format, in which each line is a valid independent JSON value, therefore instead of (1), you should use (2)):



(1)



[
{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" },
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" },
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }
]


(2)



{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" }
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" }
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }




UPDATE:



Here a step-by-step guide in order to show how this works:



Create a JSON file (file.json in my case) with the content I shared (make sure to remove the array brackets and also the commas , at the end of each line:



$ cat file.json
{ "item_name": "dfkhjf", "gtin": "123456", "brand": "Om-Publication","category_name": "books", "country_code": "IN", "marktet_place": "india", "price": 2239, "sellerId": 234, "create_time": "2017-07-19T16:00:46.000Z" }
{ "item_name": "toy-gun", "gtin": "1234234445", "brand": "Toy", "category_name": "toy", "country_code": "IN", "marktet_place": "flipMe", "price": 2239, "sellerId": 234, "create_time": "2017-08-19T16:00:46.000Z" }
{ "item_name": "Drone", "gtin": "12342356456", "brand": "Drone-XX", "category_name": "drone", "country_code": "IN", "marktet_place": "drone-maker", "price": 2239, "sellerId": 234, "create_time": "2017-09-19T16:00:46.000Z" }


Load the file to BQ, running a command like below:



$ bq load --autodetect --source_format=NEWLINE_DELIMITED_JSON dataset.table file.json                                   
Upload complete.
Waiting on bqjob_XXXXXXXXXXX ... (1s) Current status: DONE


Now query the table in order to check that the content was uploaded correctly:



$ bq query --use_legacy_sql=false "SELECT * FROM dataset.table"
Waiting on bqjob_r3ef14ac0d0a6c856_000001681819e9fc_1 ... (0s) Current status: DONE
+----------+-------+---------------------+---------------+----------------+--------------+---------------+-------------+-----------+
| sellerId | price | create_time | marktet_place | brand | country_code | category_name | gtin | item_name |
+----------+-------+---------------------+---------------+----------------+--------------+---------------+-------------+-----------+
| 234 | 2239 | 2017-07-19 16:00:46 | india | Om-Publication | IN | books | 123456 | dfkhjf |
| 234 | 2239 | 2017-08-19 16:00:46 | flipMe | Toy | IN | toy | 1234234445 | toy-gun |
| 234 | 2239 | 2017-09-19 16:00:46 | drone-maker | Drone-XX | IN | drone | 12342356456 | Drone |
+----------+-------+---------------------+---------------+----------------+--------------+---------------+-------------+-----------+






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 4 at 9:25

























answered Jan 3 at 12:59









dsestodsesto

4,46121226




4,46121226













  • @jyoti I have updated my answer, showing the step-by-step process to make the load work. If you still encounter issues with this, please be as specific as possible with the issues / errors that you are seeing.

    – dsesto
    Jan 4 at 9:26











  • Thanks. It works fine.

    – jyoti
    Jan 4 at 10:36



















  • @jyoti I have updated my answer, showing the step-by-step process to make the load work. If you still encounter issues with this, please be as specific as possible with the issues / errors that you are seeing.

    – dsesto
    Jan 4 at 9:26











  • Thanks. It works fine.

    – jyoti
    Jan 4 at 10:36

















@jyoti I have updated my answer, showing the step-by-step process to make the load work. If you still encounter issues with this, please be as specific as possible with the issues / errors that you are seeing.

– dsesto
Jan 4 at 9:26





@jyoti I have updated my answer, showing the step-by-step process to make the load work. If you still encounter issues with this, please be as specific as possible with the issues / errors that you are seeing.

– dsesto
Jan 4 at 9:26













Thanks. It works fine.

– jyoti
Jan 4 at 10:36





Thanks. It works fine.

– jyoti
Jan 4 at 10:36




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020867%2fgetting-error-while-inserting-array-of-json-to-bigquery%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith