简体   繁体   中英

How to extract data from a JSON tye column which field name has special characters?

I have the following JSON type column in a Bigquery table. I've been able to extract several columns from this JSON type column using JSON_EXTRACT_SCALAR(column_name,"$.field_name"), but when I tried to do the same thing whit the field named &&products, I retrive the following output.

Invalid token in JSONPath at: .&&products

Here is an example of the JSON:

{"page_siteSection":"Juguetería","page_pageType":"product list page","page_loginStatus":"guest","showPlp":"1","page_canal":"app","page_appSection":"showPlp","page":"plp","page_number":"1","page_previousPageName":"MAPPING_NOT_FOUND","page_pageName":"plp: Juguetería","sku_list":"882696728,882575700,882401880,882008929,882583634,881893746,881646404,881629066,882583930,882133550,882135129,882564681,881969441,881663405,882643810,882647787,881956442,882568189,882647793,882557468,882564687,881962673,882561842,882561846,113342573,114320584,16765239,18722548,114270995,114271159,114413499,114413451,18977742,19097731,114320991,17957150,19453119,19388261,19378246,19140238,19091371,19388285,18017648,19388276,19254877,19182189,114271264,113373122","hometag":"V-DY|Vitrina|1|x|2|null|product list page|HO_V2_JUG_1389|https:\/\/\/v3\/assets\/bltf4ed0b9a176c126e\/bltc490f6289eb561f9\/6387d247fa61d3109a1043de\/2-vitrina-w49-juguetería-app-av_v2.png","page_sessionId":"","sis_experience":"olo","&&products":";882696728;;;;position={1},;882575700;;;;position={2},;882401880;;;;position={3},;882008929;;;;position={4},;882583634;;;;position={5},;881893746;;;;position={6},;881646404;;;;position={7},;881629066;;;;position={8},;882583930;;;;position={9},;882133550;;;;position={10},;882135129;;;;position={11},;882564681;;;;position={12},;881969441;;;;position={13},;881663405;;;;position={14},;882643810;;;;position={15},;882647787;;;;position={16},;881956442;;;;position={17},;882568189;;;;position={18},;882647793;;;;position={19},;882557468;;;;position={20},;882564687;;;;position={21},;881962673;;;;position={22},;882561842;;;;position={23},;882561846;;;;position={24},;113342573;;;;position={25},;114320584;;;;position={26},;16765239;;;;position={27},;18722548;;;;position={28},;114270995;;;;position={29},;114271159;;;;position={30},;114413499;;;;position={31},;114413451;;;;position={32},;18977742;;;;position={33},;19097731;;;;position={34},;114320991;;;;position={35},;17957150;;;;position={36},;19453119;;;;position={37},;19388261;;;;position={38},;19378246;;;;position={39},;19140238;;;;position={40},;19091371;;;;position={41},;19388285;;;;position={42},;18017648;;;;position={43},;19388276;;;;position={44},;19254877;;;;position={45},;19182189;;;;position={46},;114271264;;;;position={47},;113373122;;;;position={48}"}```


Since I've been able to extract fields such as page_section and others, when I use JSON_EXTRACT_SCALAR(column_name,"$.&&products") it does not work for me and shows the above error. Any hints?



It won't work since it is not a valid JSONPath.

I guess the only option you have is to take that JSON field as a STRING, perform some replace operations to adjust the JSON to the standard rules and then CAST it again to JSON and perform your JSON Path queries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM