Unexpected token } in JSON at position 378 - json

Trying to figure out why the top .json file returns an error while the bottom works fine. (sorry if format is terrible, first post here) working code is from GitHub so i don't have very much knowledge of the 'inner workings'(mac OS). TIA
{
"regions": [
"cville",
"tech",
"downtown",
"outskirts",
"allregions"
],
"region_subregions": {
"cville": ["tech", "downtown"],
"allregions": ["cville", "tech", "downtown", "northcv", "southcv", "westcv", "canecreek"]
},
"region_neighborhoods": {
"southcv": ["parkview", "sink", "fairground"],
}
}
{
"regions": [
"sf",
"eastsf",
"centralsf",
"westsf",
"southsf",
"peninsula",
"sanjose",
"marin",
"eastbay",
"sacramento",
"allregions"
],
"region_subregions": {
"sf": ["eastsf", "centralsf", "westsf"],
"allregions": ["eastsf", "centralsf", "westsf", "southsf", "peninsula", "sanjose", "marin", "eastbay", "sacramento"]
},
"region_neighborhoods": {
"eastsf": ["embarcadero-p39-northbeach", "missionbay-dogpatch", "soma-ferry_bldg", "fidi-union_sq", "tenderloin-civic_center", "nob-russian_hill"],
"centralsf": ["haight-castro", "mission-dolores", "fillmore-hayes_valley"],
"westsf": ["presidio-marina", "richmond-gg_park", "sunset-", "lakeview-lake_merced"],
"southsf": ["glen_park-twin_peaks", "ingleside-", "excelsior-portola", "outer_mission-cow_palace", "bayview-", "south_city-brisbane", "daly_city-pacifica"],
"peninsula": ["half_moon_bay-coast", "san_bruno-burlingame", "san_mateo-foster_city", "belmont-sc-rws", "redwood_city-palo_alto", "mt-view_sunnyvale"],
"sanjose": ["san-jose"],
"marin": ["marin-"],
"eastbay": ["oakland-", "berkeley-", "east-bay"],
"sacramento": ["sacramento-"]
}
}

It's due to the trailing comma on this line
"southcv": ["parkview", "sink", "fairground"],

Related

Replace piece of json

I have a big .json file with geodata. Its a piece of this file. It has a repeating structure.
I want to save info about "id" and "area_value" and remove or replace other data.
With this structure.
{'Number':['id'],'Area sq.m.': ['area_value'],'Forest cov':'None','Status':'None'}
What method can be optimal for solving this problem?
Thanks!
{
"type":"FeatureCollection",
"crs":{
"type":"name",
"properties":{
"name":"EPSG:4326"
}
},
"features":[
{
"type":"Feature",
"properties":{
"date_create":"15.03.2008",
"statecd":"06",
"cc_date_approval":null,
"children":null,
"adate":"23.08.2017",
"cc_date_entering":"01.01.2014",
"rifr_cnt":null,
"parcel_build_attrs":null,
"rifr":null,
"sale_date":null,
"area_unit":"055",
"util_code":null,
"util_by_doc":null,
"area_value":115558.0,
"application_date":null,
"sale":null,
"cad_unit":"383",
"kvartal":"69:3:11",
"parent_id":"69:3:11:248",
"sale_cnt":null,
"sale_doc_date":null,
"date_cost":null,
"category_type":"003008000000",
"rifr_dep":null,
"kvartal_cn":"69:03:0000011",
"parent_cn":"69:03:0000011:248",
"cn":"69:03:0000011:245",
"is_big":false,
"rifr_dep_info":null,
"sale_dep":null,
"sale_dep_uo":null,
"parcel_build":false,
"id":"69:3:11:245",
"address":"\u0422\u0432\u0435\u0440\u0441\u043a\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c, \u0440-\u043d. \u0411\u0435\u043b\u044c\u0441\u043a\u0438\u0439, \u0441/\u043f. \u0415\u0433\u043e\u0440\u044c\u0435\u0432\u0441\u043a\u043e\u0435, \u0434. \u041e\u0441\u0438\u043f\u043e\u0432\u043e",
"area_type":"009",
"parcel_type":"parcel",
"sale_doc_num":null,
"sale_doc_type":null,
"sale_price":null,
"cad_cost":139698.06,
"fp":null,
"center":{
"x":33.14727379331379,
"y":55.87764081906541
}
}
}
You can try along the following lines:
import json
# some JSON:
x = '{ "name":"John", "age":30, "city":"New York"}'
# parse x:
y = json.loads(x)
# the result is a Python dictionary:
print(y["age"])

How to run JSONiq from JSON with try.zorba.io

I need to write a JSONiq expression that lists only the name of the products that cost at least 3. This is my JSON file which i had typed in the XQuery section:
{ "supermarket_visit":{
"date":"08032019",
"bought":[
"item",{
"type":"confectionary",
"item_name":"Kit_Kat",
"number": 3,
"individual_price": 3.5
},
"item",{
"type":"drinks",
"item_name":"Coca_Cola",
"number": 2,
"individual_price": 3
},
"item",{
"type":"fruits",
"item_name":"apples",
"number": "some"
}
], 
"next_visit":[
"item",{
"type":"stationary",
"item_name":"A4_paper",
"number": 1
},
"item",{
"type":"stationary",
"item_name":"pen",
"number": 2
}
]
}
}
and this is my JSONiq Xquery JSONiq command, which i dont really know where to type in try.zorba.io:
let $x := find("supermarket_visit")
for $x in $supermarket.bought let $i := $x.item
where $i.individual_price <=3
return $i.item_name
I am getting many errors in try.zorba.io and im really new to JSONiq and JSON. Is something wrong with my JSON or JSONiq part?
The following selection works for me at the site you linked to:
jsoniq version "1.0";
{ "supermarket_visit":{
"date":"08032019",
"bought":[
"item",{
"type":"confectionary",
"item_name":"Kit_Kat",
"number": 3,
"individual_price": 3.5
},
"item",{
"type":"drinks",
"item_name":"Coca_Cola",
"number": 2,
"individual_price": 3
},
"item",{
"type":"fruits",
"item_name":"apples",
"number": "some"
}
],
"next_visit":[
"item",{
"type":"stationary",
"item_name":"A4_paper",
"number": 1
},
"item",{
"type":"stationary",
"item_name":"pen",
"number": 2
}
]
}
}.supermarket_visit.bought()[$$ instance of object and $$.individual_price le 3].item_name
The original query can be slightly modified to (in order to keep a FLWOR expression):
jsoniq version "1.0";
let $document := { (: put the document here :) }
for $x in $document.supermarket_visit.bought[]
where $x instance of object and $x.individual_price le 3
return $x.item_name
Note that try.zorba.io is an older version of Zorba (2.9) that does not implement the latest, stable JSONiq version. This is why () must be used instead of [] on this specific page. If you download the latest version of Zorba, the above query should work.
Also, the original document provided in the question is not well-formed JSON, because it contains a special em space character (Unicode 2003) on the line above "next_visit". This character must be removed for this JSON to be parsed successfully.

Node.js how do you read a JSON with an element that is a HTTP address

OK I just ran into an issue. I am using Auth0 to create users with different rights (not scopes just rights) in the App Metadata. When I decode the Token I get this json:
{
"iss": "https://testing.auth0.com/",
"sub": "auth0|58e7bae154941844b507eaf5",
"aud": "OSBkLd832tIhpDe0QFJbQ9vutgB2s6cJ",
"exp": 1497016797,
"iat": 1496980797,
"https://thetestgroup.com/app_metadata": {
"is_admin": true
}
}
As you can see the app metadata is in the element "https://thetestgroup.com/app_metadata". Normally I would just do something like this in my code (auth.payload.iat) to get the iat but for the app_metadata it rejects it because of the :. Is there a good way to get at that data?
ok lets talk javascript (node) and your json
Firefox Scratchpad (Shift-F4)
var x = {
"iss": "https://testing.auth0.com/",
"sub": "auth0|58e7bae154941844b507eaf5",
"aud": "OSBkLd832tIhpDe0QFJbQ9vutgB2s6cJ",
"exp": 1497016797,
"iat": 1496980797,
"https://thetestgroup.com/app_metadata": {
"is_admin": true
}
}
x['https://thetestgroup.com/app_metadata'].is_admin // hit run
/*
true
*/
node.js
~ $ node -v
v8.1.0
~ $ node
> var x = {
... "iss": "https://testing.auth0.com/",
... "sub": "auth0|58e7bae154941844b507eaf5",
... "aud": "OSBkLd832tIhpDe0QFJbQ9vutgB2s6cJ",
... "exp": 1497016797,
... "iat": 1496980797,
... "https://thetestgroup.com/app_metadata": {
..... "is_admin": true
..... }
... }
undefined
> x['https://thetestgroup.com/app_metadata'].is_admin
true
>
Please provide a mcve since pure JS and JSON are quite happily using the (strange) key - as demonstrated.

how can i read a custom DataSource(*.json) by Cesium

i have a grb2 file, i use grib2json covert it to .json, here is the json code:
[
{
"header":{
"discipline":0,
"disciplineName":"Meteorological products",
"gribEdition":2,
"gribLength":455039,
"center":7,
"centerName":"US National Weather Service - NCEP(WMC)",
"subcenter":0,
"refTime":"2016-10-05T12:00:00.000Z",
"significanceOfRT":1,
"significanceOfRTName":"Start of forecast",
"productStatus":0,
"productStatusName":"Operational products",
"productType":1,
"productTypeName":"Forecast products",
"productDefinitionTemplate":0,
"productDefinitionTemplateName":"Analysis/forecast at horizontal level/layer at a point in time",
"parameterCategory":2,
"parameterCategoryName":"Momentum",
"parameterNumber":3,
"parameterNumberName":"V-component_of_wind",
"parameterUnit":"m.s-1",
"genProcessType":2,
"genProcessTypeName":"Forecast",
"forecastTime":0,
"surface1Type":103,
"surface1TypeName":"Specified height level above ground",
"surface1Value":10.0,
"surface2Type":255,
"surface2TypeName":"Missing",
"surface2Value":0.0,
"gridDefinitionTemplate":0,
"gridDefinitionTemplateName":"Latitude_Longitude",
"numberPoints":259920,
"shape":6,
"shapeName":"Earth spherical with radius of 6,371,229.0 m",
"gridUnits":"degrees",
"resolution":48,
"winds":"true",
"scanMode":0,
"nx":720,
"ny":361,
"basicAngle":0,
"subDivisions":0,
"lo1":0.0,
"la1":90.0,
"lo2":359.5,
"la2":-90.0,
"dx":0.5,
"dy":0.5
},
"data":[
3.92,
3.89,
......
-3.06,
-3.07
]
}
]
when i use Cesium1.26 to read the json file, it works, but i can't get the header and data, can anyone help me about this problem?

JSON.parse() unexpected token error

I am getting unexpected token error when trying to parse this JSON string
$scope.feeds = JSON.parse('[{"id":"212216417436_10152811286407437","from":{ "category":"Movie","name":"The Lord of the Rings Trilogy","id":"212216417436"},"story":"The Lord of the Rings Trilogy shared The Hobbit\'s photo.","picture":"https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-xaf1/v/t1.0-9/s130x130/1912397_736719376363670_7288336626443028501_n.jpg?oh=a7e83093f61fafa7909ff84263f989e4&oe=54B4481D&__gda__=1420472696_dbd6462629a00e218c849c5ed7b49c44","link":"https://www.facebook.com/TheHobbitMovie/photos/a.291674244201521.63650.160617097307237/736719376363670/?type=1","name":"Timeline Photos","caption":"\"I have the only right.\" \n\nWhat is your favorite Thorin quote from #TheHobbit?","properties":[ { "name":"By","text":"The Hobbit","href":"https://www.facebook.com/TheHobbitMovie?ref=stream"}],"icon":"https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif","actions":[ { "name":"Comment","link":"https://www.facebook.com/212216417436/posts/10152811286407437"},{ "name":"Like","link":"https://www.facebook.com/212216417436/posts/10152811286407437"}],"privacy":{ "value":""},"type":"photo","status_type":"shared_story","object_id":"736719376363670","application":{ "name":"Photos","id":"2305272732"},"created_time":"2014-10-12T21:35:41+0000","updated_time":"2014-10-12T21:37:17+0000"},{ "id":"21785951839_10152794856921840","from":{ "category":"App page","name":"9GAG","id":"21785951839"},"message":"Must NOT let my girlfriend see this!\nhttp://9gag.tv/p/a9OrlY?ref=fbl9\n\nWatch more awesome videos on your phone:\nAndroid ► http://goo.gl/Rbi9FP\niPhone/iPad ► http://goo.gl/NFMm9p","picture":"https://fbexternal-a.akamaihd.net/safe_image.php?d=AQCee84KqIBIdnIX&w=158&h=158&url=http%3A%2F%2Fd1d4324mp0stc8.cloudfront.net%2Fmedia%2Fphoto%2FpPgXmO5QJ_600w_v1.jpg","link":"http://9gag.tv/p/a9OrlY?ref=fbl9","name":"This \"Marry Me\" Lip-Sync Proposal Is So Touching And Amazing | 9GAG.tv","caption":"9gag.tv","description":"This sets the bar pretty high!","icon":"https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif","actions":[ { "name":"Comment","link":"https://www.facebook.com/21785951839/posts/10152794856921840"},{ "name":"Like","link":"https://www.facebook.com/21785951839/posts/10152794856921840"}],"privacy":{ "value":""},"type":"link","status_type":"shared_story","created_time":"2014-10-12T21:15:00+0000","updated_time":"2014-10-12T21:15:46+0000","shares":{ "count":160}}]');
Expanded string object:
{
"id":"212216417436_10152811286407437",
"from":{
"category":"Movie",
"name":"The Lord of the Rings Trilogy",
"id":"212216417436"
},
"story":"The Lord of the Rings Trilogy shared The Hobbit\'s photo.",
"picture":"https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-xaf1/v/t1.0-9/s130x130/1912397_736719376363670_7288336626443028501_n.jpg?oh=a7e83093f61fafa7909ff84263f989e4&oe=54B4481D&__gda__=1420472696_dbd6462629a00e218c849c5ed7b49c44",
"link":"https://www.facebook.com/TheHobbitMovie/photos/a.291674244201521.63650.160617097307237/736719376363670/?type=1",
"name":"Timeline Photos",
"caption":"\"I have the only right.\" \n\nWhat is your favorite Thorin quote from #TheHobbit?",
"properties":[
{
"name":"By",
"text":"The Hobbit",
"href":"https://www.facebook.com/TheHobbitMovie?ref=stream"
}
],
"icon":"https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif",
"actions":[
{
"name":"Comment",
"link":"https://www.facebook.com/212216417436/posts/10152811286407437"
},
{
"name":"Like",
"link":"https://www.facebook.com/212216417436/posts/10152811286407437"
}
],
"privacy":{
"value":""
},
"type":"photo",
"status_type":"shared_story",
"object_id":"736719376363670",
"application":{
"name":"Photos",
"id":"2305272732"
},
"created_time":"2014-10-12T21:35:41+0000",
"updated_time":"2014-10-12T21:37:17+0000"
},
{
"id":"21785951839_10152794856921840",
"from":{
"category":"App page",
"name":"9GAG",
"id":"21785951839"
},
"message":"Must NOT let my girlfriend see this!\nhttp://9gag.tv/p/a9OrlY?ref=fbl9\n\nWatch more awesome videos on your phone:\nAndroid ► http://goo.gl/Rbi9FP\niPhone/iPad ► http://goo.gl/NFMm9p",
"picture":"https://fbexternal-a.akamaihd.net/safe_image.php?d=AQCee84KqIBIdnIX&w=158&h=158&url=http%3A%2F%2Fd1d4324mp0stc8.cloudfront.net%2Fmedia%2Fphoto%2FpPgXmO5QJ_600w_v1.jpg",
"link":"http://9gag.tv/p/a9OrlY?ref=fbl9",
"name":"This \"Marry Me\" Lip-Sync Proposal Is So Touching And Amazing | 9GAG.tv",
"caption":"9gag.tv",
"description":"This sets the bar pretty high!",
"icon":"https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif",
"actions":[
{
"name":"Comment",
"link":"https://www.facebook.com/21785951839/posts/10152794856921840"
},
{
"name":"Like",
"link":"https://www.facebook.com/21785951839/posts/10152794856921840"
}
],
"privacy":{
"value":""
},
"type":"link",
"status_type":"shared_story",
"created_time":"2014-10-12T21:15:00+0000",
"updated_time":"2014-10-12T21:15:46+0000",
"shares":{
"count":160
}
}
verify your json string. If it is ok try this:
var jsonStr="your json string";
var json=JSON.stringify(jsonStr);
json=JSON.parse(json)
When you're typing a string in javascript, the \ is treated as escaping character, while you need it in your json to actually be a \ and not escaping character.
You need to change the \" to \\" and \n to \\n, while keeping the \' because it is already an escaping character and it should be parsed okay