How to fix error 822 unexpected token at "json"? - json

I have a VBA file that has been working for years with a POST to API function to create products on Shopify. It has suddenly and for non identified reason stopped working around April 15th 2019. It gives the following error:
"error": "822: unexpected token at [my JSON string]
This is what the JSON string looks like (you can find a more complete one at the end of this post):
{
"product": {
"title": "Lunettes",
"body_html": "some long text",
"vendor": "Tom Ford",
"product_type": "lunettes enfant adolescents",
"published": false,
"tags": "some tags",
"variants": [
{
"option1": "default title",
"price": "199",
"sku": "1",
"weight_unit": "g"
}
],
"options": [
{
"name": "title",
"position": 1,
"values": [
"default title"
]
}
]
}
}
What I have already tried:
check the URL with correct API key and token/password
tried adding the latest released Shopify API version to the CURL : 2019-04
check the syntax of the JSON string (comas, {, etc)
Basically tried everything I knew. Please help if you have any clue.
the more complete Json_String is :
{"product":{"title":"Lunettes TF5501 ","body_html":"TEXT,<div style=\"text-align: center;\"><img alt=\"Dimensions Lunettes Varionet TF5501 Argent\" src=\"https://cdn.shopify.com/s/files/1/0855/6878/files/Lunettes.png?15354686291941720795\" style=\"float: none; display: block; margin-left: auto; margin-right: auto;\" /></div><div style=\"overflow-x: auto;\"> <table width=\"100%\"> <tbody><tr style=\"background-color: #98ffaf;\"><td style=\"text-align: center;\">140 mm</td><td style=\"text-align: center;\">54 mm</td><td style=\"text-align: center;\">38 mm</td><td style=\"text-align: center;\">18 mm</td><td style=\"text-align: center;\">145 mm</td></tr></tbody></table></div>","vendor":"Brand","product_type":"lunettes anti lumière bleue","published":false,"tags":"meta-filter-Marque-Varionet,meta-filter-Forme-Rectangle,meta-filter-Genre-Unisex,meta-filter-Genre-Homme,meta-filter-Genre-Femme,meta-filter-Couleur-Argent","variants":[{"option1":"default title","price":"199","sku":"tom ford tf5501016","position":1,"grams":"100","inventory_policy":"deny","compare_at_price":"339","fulfillment_service":"logisticien-mavu","inventory_management":"shopify","option_1":"default title","requires_shipping":true,"taxable":true,"inventory_quantity":1,"weight_unit":"g"}],"options":[{"name":"title","position":1,"values":["default title"] }]
}}
Thanks!
Youri

The first JSON you provided (please correct it to a code-block) is correct, but when parsing your more complete Json_string, you'll see that you have too much curly brackets at the end:
{
"product": {
"title": "Lunettes TF5501 ",
"body_html": "TEXT,https://cdn.shopify.com/s/files/1/0855/6878/files/Lunettes.png?15354686291941720795\" style=\"float: none; display: block; margin-left: auto; margin-right: auto;\" /> 140 mm54 mm38 mm18 mm145 mm",
"vendor": "Brand",
"product_type": "lunettes anti lumière bleue",
"published": false,
"tags": "meta-filter-Marque-Varionet,meta-filter-Forme-Rectangle,meta-filter-Genre-Unisex,meta-filter-Genre-Homme,meta-filter-Genre-Femme,meta-filter-Couleur-Argent",
"variants": [{
"option1": "default title",
"price": "199",
"sku": "tom ford tf5501016",
"position": 1,
"grams": "100",
"inventory_policy": "deny",
"compare_at_price": "339",
"fulfillment_service": "logisticien-mavu",
"inventory_management": "shopify",
"option_1": "default title",
"requires_shipping": true,
"taxable": true,
"inventory_quantity": 1,
"weight_unit": "g"
}],
"options": [{
"name": "title",
"position": 1,
"values": ["default title"]
}]
}
}
}
}
Try removing the last 2 curly brackets

Thanks for your replies
#David : I've seen the link https://community.shopify.com/c/Shopify-APIs-SDKs/error-gt-822-unexpected-token-at-price-rule/td-p/480430 , but i don't understand where and how i must use the 'X-Shopify-Access-Token' in VBA code, should it be added in the objHTTP.setRequestHeader? This is the API key, the Password or the "shared secret" ?
#QHarr : my posting parameters are :
Dim result As String
Dim objHTTP As Object
Url = "http://API-KEY:PASSWORD#SHOP-NAME.myshopify.com/admin/api/2019-04/products.json"
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.Open "POST", Url, False, "API-KEY", "PASSWORD"
objHTTP.setRequestHeader "Content-Type", "application/json"
objHTTP.send ("json_string")
result = objHTTP.responseText

Related

Debitoor API is returning 400 bad request

I would like to create invoices by my PHP script. But before I am able to program this I would like to understand the API from Debitoor.
In order to create an invoice you have to create a draft invoice first. You can find this here: /api/sales/draftinvoices/v3.
I have set all the requested parameters to use the the /api/sales/draftinvoices/v3 function however, I always get a 400 Bad Request response back.. The reason is the schema.
Can you guys tell me where my failure is?
I would guess is something with the "lines"... but I would say it's all correct...
This is my request:
Request as text:
{
"date": "2018-05-06",
"dueDate": "2018-05-13",
"notes": "Diese Rechnung ist vom Backend erstellt worden.",
"customerName": "Max Mustermann",
"customerAddress": "Mustermann Stra\u00dfe",
"customerCountry": "DE",
"currency": "EUR",
"languageCode": "de-DE",
"recargoTaxEnabled": false,
"sent": false,
"viewed": false,
"displayAsPaid": false,
"lines": {
"taxEnabled": "false",
"description": "Leistungszeitraum 06.04.2018 - 05.05.2018",
"taxRate": "1.19",
"productOrService": "product"
}
}
This is the response I get back:
As text:
{
"message": "Error validating against schema",
"id": "9905636b-fb65-41a0-8d25-4aa096d5347d",
"code": "schema",
"errors": [
{
"message": "is the wrong type",
"value": {
"taxEnabled": "false",
"description": "Leistungszeitraum 06.04.2018 - 05.05.2018",
"taxRate": "1.19",
"productOrService": "product"
},
"type": "array",
"property": "lines"
}
],
"body": {
"date": "2018-05-06",
"dueDate": "2018-05-13",
"notes": "Diese Rechnung ist vom Backend erstellt worden.",
"customerName": "Max Mustermann",
"customerAddress": "Mustermann Stra\u00dfe",
"customerCountry": "DE",
"currency": "EUR",
"languageCode": "de-DE",
"recargoTaxEnabled": false,
"sent": false,
"viewed": false,
"displayAsPaid": false,
"lines": {
"taxEnabled": "false",
"description": "Leistungszeitraum 06.04.2018 - 05.05.2018",
"taxRate": "1.19",
"productOrService": "product"
}
}
}
Kind regards and Thank You!
Thank you for using the Debitoor API
You are correct. Your problem is with the lines. Lines should be an array. You have only send a single object.
Another issue is that you provide taxEnabled: false and taxRate: 1.19. If you provide taxEnabled as false you should set the taxRate to 0. Remember that taxRate should be between 0 and 100 with a maximum of two decimals
Your request should look something like this instead:
{
"lines": [
{
"taxEnabled": false,
"description": "Leistungszeitraum 06.04.2018 - 05.05.2018",
"taxRate": 0,
"quantity": 1,
"unitNetPrice": 1,
"productOrService": "product"
}
]
Best regards,
Carsten
Mobile developer # Debitoor

Get "id" value from httpget json response

Below is my JSON output received post the HttpGet successful execution.
{
"results": [{
"id": "1310760",
"type": "page",
"status": "current",
"title": "UniversalProfile Release Test",
"extensions": {
"position": 9
},
"_links": {
"webui": "/display/ds/UniversalProfile+Release+Test",
"tinyui": "/x/KAAU",
"self": "http:1310760"
},
"_expandable": {
"container": "/rest/api/space/ds",
"metadata": "",
"operations": "",
"children": "/rest/api/content/1310760/child",
"history": "/rest/api/content/1310760/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/1310760/descendant",
"space": "/rest/api/space/ds"
}
}],
"start": 0,
"limit": 25,
"size": 1,
"_links": {
"self": "UniversalProfile+Release+Test",
"base": "https://alim4azad.atlassian.net/wiki",
"context": "/wiki"
}
}
I am trying to extract the value for "id" but have been unsuccessful so far.
If your JSON is in the variable output in Javascript, it'd be :
output.results[0]["id"]
Like console.log(output.results[0]["id"]).
Your results section contains arrays. You want the first (0), and then the key id.
Looking at that resulting JSON hurts my brain.
Assuming you are using JavaScript, try this: output.results[0]['id']
Try This:
JSONObject jsonObject = new JSONObject(data);
JSONArray jsonArray = jsonObject.getJSONArray("results");
JSONObject jsonObject1 = jsonArray.getJSONObject(0).getString("id");
Finally i found a solution for it . Below is the solution.
JSONArray results = getbodyPage.getJSONArray("results");
JSONObject first = results.getJSONObject(0);
Long id = first.getLong("id"); // Get id of the found page
System.out.println("INFO : Found ID - " + id);
Thank you all for your valuable inputs.

Serialize the response from backend to store ember store

My response from backend is not in form which ember store. I am not able to serialize the response.
response.json
[{
"pk": 127,
"url": "http://example.com/api/galleries/127/",
"gallery_name": "Faces",
"thumbnail_url": "https://example.cloud.net/galleryThumbs/2656a05c-4ec7-3eea-8c5e-d8019454d443.jpg",
"time": "1 month ago",
"description": "Created by user",
"is_following": true,
"feedPhotos": [{
"pk": 624,
"url": "http://example.com/api/photos/624/",
"profilePic": "https://example.cloud.net/userDPs/50906ce2-394d-39c8-9261-8cf78e3611c2.jpg",
"userName": "Nabeela",
"userKarma": 915,
"caption": "Old woman spinning her 'chhos-khor' ...a rotation of which is equivalent to the recitation of a mantra.",
"numComments": 0,
"owner": "http://example.com/api/users/44/",
"time": "1 month ago",
"photo_url": "https://example.cloud.net/photos/9cbd6423-3bc5-36e0-b8b4-d725efb3249a.jpg",
"comments_url": "http://example.com/api/photos/624/comments/",
"numFives": 4,
"fivers_url": "http://example.com/api/photogalleries/1362/fivers/",
"fivers_pk": 1362,
"fullphoto_url": "http://example.com/api/photogalleries/1362/photo/",
"fullphoto_pk": 1362,
"is_fived": true,
"hiFiveKarma": 1,
"owner_pk": 44,
"userFirstName": "Nabeela",
"is_bookmarked": false
}, {
"pk": 574,
"url": "http://example.com/api/photos/574/",
"profilePic": "https://example.cloud.net/userDPs/b6f69e4e-980d-3cc3-8b3e-3eb1a7f21350.jpg",
"userName": "Rohini",
"userKarma": 194,
"caption": "Life # Myanmar!",
"numComments": 0,
"owner": "http://example.com/api/users/45/",
"time": "2 months ago",
"photo_url": "https://example.cloud.net/photos/eeae72d5-d6af-391e-a218-b442c0c7e34e.jpg",
"comments_url": "http://example.com/api/photos/574/comments/",
"numFives": 2,
"fivers_url": "http://example.com/api/photogalleries/1303/fivers/",
"fivers_pk": 1303,
"fullphoto_url": "http://example.com/api/photogalleries/1303/photo/",
"fullphoto_pk": 1303,
"is_fived": false,
"hiFiveKarma": 0,
"owner_pk": 45,
"userFirstName": "Rohini",
"is_bookmarked": false
}
]
}, {
"pk": 65,
"url": "http://example.com/api/galleries/65/",
"gallery_name": "Royal",
"thumbnail_url": "https://example.cloud.net/galleryThumbs/d8a900af-1f1d-3977-8cc8-b8bb36e32be5.jpg",
"time": "2 months ago",
"description": "This is a gallery about Royal",
"is_following": false,
"feedPhotos": [{
"pk": 347,
"url": "http://example.com/api/photos/347/",
"profilePic": "https://example.cloud.net/userDPs/50906ce2-394d-39c8-9261-8cf78e3611c2.jpg",
"userName": "Nabeela",
"userKarma": 915,
"caption": "I cannot forget the name of this palace - Moti Mahal (translation: Pearl Palace). Indescribably beautiful, ainnit! at Mehrangarh fort, Jodhp",
"numComments": 0,
"owner": "http://example.com/api/users/44/",
"time": "2 months ago",
"photo_url": "https://example.cloud.net/photos/958ed406-708e-3f01-a2f4-9467cd709fdd.jpg",
"comments_url": "http://example.com/api/photos/347/comments/",
"numFives": 4,
"fivers_url": "http://example.com/api/photogalleries/759/fivers/",
"fivers_pk": 759,
"fullphoto_url": "http://example.com/api/photogalleries/759/photo/",
"fullphoto_pk": 759,
"is_fived": false,
"hiFiveKarma": 0,
"owner_pk": 44,
"userFirstName": "Nabeela",
"is_bookmarked": false
}, {
"pk": 593,
"url": "http://example.com/api/photos/593/",
"profilePic": "https://example.cloud.net/userDPs/95ac6974-f7df-338c-ab84-99fa1df7514c.jpg",
"userName": "Vikanshu",
"userKarma": 932,
"caption": "Marvelous architecture!! in Florence, Italy",
"numComments": 0,
"owner": "http://example.com/api/users/48/",
"time": "1 month ago",
"photo_url": "https://example.cloud.net/photos/7a86eb37-6c68-3d6c-b6cf-2e3b74d330dd.jpg",
"comments_url": "http://example.com/api/photos/593/comments/",
"numFives": 4,
"fivers_url": "http://example.com/api/photogalleries/1363/fivers/",
"fivers_pk": 1363,
"fullphoto_url": "http://example.com/api/photogalleries/1363/photo/",
"fullphoto_pk": 1363,
"is_fived": false,
"hiFiveKarma": 0,
"owner_pk": 48,
"userFirstName": "Vikanshu",
"is_bookmarked": false
}]
}]
How do I serialize this using JSONPISerailizer or any other serializer in ember-cli so that it gets stored in ember store
Reference jsonapi.org
++++Top Level:
Root:
A JSON object must be root of every JSON API request response.
A document must contain at least one top-level members:
1. data: documents "primary data"
2. errors: an array of error objects (id,status,code,title....)
3. meta: a meta object that contains non-standard meta-information (copyright,author...)
member data and errors must not co-exist together.
"data"{}
+++++Resource Objects
1. A resource object MUST contain atleast following top-level member
*id
*type
```
//structure-1
//for galleries
{
"data": {
"type": "galleries",
"id": "1"
}
}
//for photos
{
"data": {
"type": "photos",
"id": "1"
}
}
```
In addition, a resource object may contain any of these top-level members
*attributes
*relationship
*links
*meta
//added attributes first
```
//structure-2
//for galleries
{
"data": {
"type": "galleries",
"id": "1",
"attributes": {
"galleryName": "Faces"
"thumbnailUrl:"https://example.cloud.net/galleryThumbs/2656a05c-4ec7.jpg",
"description": "Created by user",
}
}
}
//for photos
{
"data": {
"type": "photos",
"id": "1",
"attributes":{
userName: "Nabeela",
userKarma: 915
}
}
}
```
//Adding relationship
Relationship object must contain atleast one of the following
*links (containing atleast one of "self" or "related" resource link
*data
*meta
//link in relationship (minimum one required from link,data,meta).
//
```
//structure-3
//for galleries
{
"data":[{ //Array(square bracket as adding relationship one more item to data
"type": "galleries",
"id": "1",
"attributes": {
"galleryName": "Faces"
"thumbnailUrl:"https://example.cloud.net/galleryThumbs/2656a05c-4ec7.jpg",
"description": "Created by user",
},
"relationships":{
"links":{
"self": "https://example.cloud.net/photos/9cbd6423.jpg //"photo_url" in your payload
},
}]
}
}
```
//data in relationship
```
//structure-4
//for galleries
{
"data": [{
"type": "galleries",
"id": "1",
"attributes": {
"galleryName": "Faces"
"thumbnailUrl:"https://example.cloud.net/galleryThumbs/2656a05c-4ec7.jpg",
"description": "Created by user",
},
"relationships":{ //This has all your photo stuff
"links":{
"self": "https://example.cloud.net/photos/9cbd6423.jpg //"photo_url" in your payload
},
"data": { //picked it up from structure-1
"type": "photos",
"id": "77"
}
}]
}
}
```
//Adding related resource "included"
```
//for galleries
{
"data": [{
"type": "galleries",
"id": "1",
"attributes": {
"galleryName": "Faces"
"thumbnailUrl:"https://example.cloud.net/galleryThumbs/2656a05c-4ec7.jpg",
"description": "Created by user",
},
"relationships":{ //This has all your photo stuff
"links":{
"self": "https://example.cloud.net/photos/9cbd6423.jpg //"photo_url" in your payload
},
"data": { //picked it up from structure-1
"type": "photos",
"id": "77"
}
}],
"included":[{
"type": "photos",
"id": "77",
"attributes":{
userName: "Nabeela",
userKarma: 915
},
{
"type": "photos",
"id": "78",
"attributes":{
userName: "Nabeela",
userKarma: 915
}
}]
}
}
```
For collections. I am not confident but try this
Now for collection of galleries.
//for galleries
{
"data": [{
"type": "galleries",
"id": "1",
"attributes": {
"galleryName": "Faces"
"thumbnailUrl:"https://example.cloud.net/galleryThumbs/2656a05c-4ec7.jpg",
"description": "Created by user",
},
"relationships":{ //This has all your photo stuff
"links":{
"self": "https://example.cloud.net/photos/9cbd6423.jpg //"photo_url" in your payload
},
"data": { //picked it up from structure-1
"type": "photos",
"id": "77"
}
},{
"type": "galleries",
"id": "2",
"attributes": {
"galleryName": "Faces"
"thumbnailUrl:"https://example.cloud.net/galleryThumbs/2656a05c-4ec7.jpg",
"description": "Created by user",
},
"relationships":{ //This has all your photo stuff
"links":{
"self": "https://example.cloud.net/photos/9cbd6423.jpg //"photo_url" in your payload
},
"data": { //picked it up from structure-1
"type": "photos",
"id": "79"
}
}],
"included":[{
"type": "photos",
"id": "77",
"attributes":{
userName: "Nabeela",
userKarma: 915
},{
"type": "photos",
"id": "78",
"attributes":{
userName: "Nabeela",
userKarma: 915
},{
"type": "photos",
"id": "79",
"attributes":{
userName: "Nabeela",
userKarma: 915
}
}]
}
}
============Implementation part =================================
JSONSerializer normalization process follows these steps
*normalizeResponse : entry method.
*normalizeCreateRecordResponse : a normalizeResponse for specific operation.
*normalizeSingleResponse|normalizeArrayResponse:
- for methods like createRecord. we expect a single record back.
- for methods like findAll we expect multiple records back.
+normalize =
normalizeArray iterates and calls normalize for each of it's records
normalizeSingle call its once.
+extractID | extractAttributes | extractRelationships
= normalize delegates to these method to turn record payload into jsonAPI format
Starting with normalizeResponse method. If you open and see normalizeResponse method
in json-serializer
link normalizeResponse: https://github.com/emberjs/data/blob/v2.2.1/packages/ember-
data/lib/serializers/json-serializer.js#L192
you with find a switch case switch(requestType). If requestType if
"findRecord" then "normalizeFindRecordResponse" is called
"queryRecord" then "normalizeQueryRecordResponse" is called
"findAll" then "normalizeFindAllResponse" is called
...so on and so forth.
if you notice the parameter passed to all the methods are same as that of normalize
(...arguments) :)
**Lets start for findAll
i.e normalizeResponse -> normalizeFindAllResponse -> normalizeArrayResponse
as normalizeFindAllResponse method has only one line that call
normalizeArrayResponse.
normalizeFindAllResponse
normalizeResponse -> normalizeFindAllResponse -> normalizeArrayResponse ->
_normalizeResponse{ extractMeta,normalize }
extractMeta [extract meta information like pagination and stuff ]
if single: normalize []
example of normalize method in emberjs docs
```
import DS from 'ember-data';
export default DS.JSONSerializer.extend({
normalize: function(typeClass, hash) {
var fields = Ember.get(typeClass, 'fields');
fields.forEach(function(field) {
var payloadField = Ember.String.underscore(field);
if (field === payloadField) { return; }
hash[field] = hash[payloadField];
delete hash[payloadField];
});
return this._super.apply(this, arguments);
}
});
```
"normalizeArrayResponse calls `return this._normalizeResponse
(store,primaryModelClass,payload,id,requestType,false).
so isSingle is false for _normalizeResponse method. so we will have to push all the
related records of included array
in our case the photos which is done by below snippet from "_normalizeRespose"
method.
_normalizeResponse
```
else{
documentHash.data = payload.map((item) => {
let { data, included } = this.normalize(primaryModelClass,item);
if(included){
documentHash.included.push(...included);
}
return data;
});
return documentHash;
}
```
Things are still unclear in the context of our JSON reponse from server
but atleast we know the flow now.
Lets try to apply it for findAll ( as per the flow above).
run "ember g serializer application" //assuming you are using ember-cli and you
intend to make this serializer generic for application.
As of now I have no information how and when normalizeResponse is called. :(
I just scanned through and guess on recieving data from server the store calls
normalizeResponseHelpers which in turn calls normalizeResponse.
In any case "normalizeResponse" is going to send payload and other necessar
information to normalizeFindAllResponse(...arguments) which in turn will call
normalizeArrayResponse(...arguments) which in turn will call "_normalizeRespone".
Here is where we need to take action
for extraMeta and normalize.
+extraMeta
I am not sure if there is any meta information in you json response.
in case there is you can refer to the example mentioned in docs
extractMeta
So I guess you can directly user the normalize method from example in your application ;).
please try and check. Since i am learning ember myself I cannot guarantee it will work but it should. the lonngggg explation is my thought while i was learning the problem/solution
//app/serializers/application.js
+normalize
```
import DS from 'ember-data';
export default DS.JSONSerializer.extend({
normalize: function(typeClass, hash) {
var fields = Ember.get(typeClass, 'fields');
fields.forEach(function(field) {
var payloadField = Ember.String.underscore(field);
if (field === payloadField) { return; }
hash[field] = hash[payloadField];
delete hash[payloadField];
});
return this._super.apply(this, arguments);
}
});
```
The primary key in the JSON from server is pk. You will have to mention that too
http://emberjs.com/api/data/classes/DS.JSONSerializer.html#property_primaryKey
app/serializers/application.js
import DS from 'ember-data';
export default DS.JSONSerializer.extend({
primaryKey: 'pk'
});

hitting REST web service from vbscript

I'm using vbscript to test a REST web service which accepts json as request and responds also in json format. I'm getting HTTP 500 - Internal Server Error as response. Here's the code:
Set objStream = CreateObject("ADODB.Stream")
objStream.CharSet = "utf-8"
objStream.Open
objStream.LoadFromFile("C:\request.txt")
restRequest = objStream.ReadText()
objStream.Close
Set objStream = Nothing
contentType ="application/json"
Set oWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
oWinHttp.Open "POST", "http://czcholsint1048.prg-dc.dhl.com:8180/efoms/fulfillOrder", False
oWinHttp.setRequestHeader "Content-Type", contentType
oWinHttp.Send restRequest
response = oWinHttp.StatusText
'response' turns out as "Internal Server Error"
I just wonder whether the json i'm converting to string before sending as request is creating any problem. Maybe beacuse of vbcrlf's it has.
Below is the json i'm sending as request:
{
"fulfillOrderReq": {
"hdr": {
"messageType": "SALESORDER",
"messageID": "d264502f-aaa2-42a5-a38d-c981ccb99379", "messageVersion": "0.1",
"messageDateTime": "2015-03-20 09:48:29",
"appId": "OMS",
"clientId": "PEP-ESB",
"reqCompId": "77000001"
},
"bd": {
"orders": [
{
"order": {
"orderNumber": "BAYLINETEST512",
"salesChannelOrderNumber": "TMALLTEST512",
"shopName": "拜仁慕尼黑海外旗舰店",
"salesChannel": "天猫订单",
"payType": "支付宝",
"created": "2015-03-20 15:35:58",
"salesChannelMemberName": "mariahliu621",
"salesChannelMemberNo": "M-9837423",
"idCard": "12312",
"idType": "NATIONAL_IDENTIFICATION_NUMBER",
"cnee": {
"name": "SANTOSH",
"address1": "CHINA",
"address3": "CHINA",
"state": "CHINA",
"city": "CHINA",
"country": "CN",
"postCode": "50470",
"telephone": "18610041036",
"mobilePhone": "18610041036"
},
"cneeMemo": "",
"cneeMessage": "",
"sellerMemo": "",
"otherMemo": "",
"actualOrderAmount": "792.0",
"agioAmount": "0.0",
"discountFee": "0.0",
"deliveryCost": "70.0",
"promotionInfo": "",
"orderItems": [
{
"orderItem": {
"productNumber": "184005",
"productName": "蜂拥而至CL克 Flock CL gr.",
"skuNumber": "184005",
"skuName": "Ribéry",
"barcode": "",
"orderGroup": "0",
"productQty": "1",
"amount": "75.0",
"discountFee": "0.0",
"agioPrice": "90.0",
"price": "110.0",
"taxCharges": "100",
"untaxPrice": "50",
"dutyCharges": "9",
"refundStatus": "Normal",
"memo": ""
}
}
]
}
}
]
}
}
}
You may have seen this already however wanted to share this here since they are related. http://forum.universal-devices.com/topic/4335-vbscript-rest-example/
Option Explicit
Dim restReq, url, userName, password
Set restReq = CreateObject("Microsoft.XMLHTTP")
' Replace <node> with the address of your INSTEON device
' Additionally, any REST command will work here
url = "http://isy/rest/nodes/<node>/ST"
' If auth is required, replace the userName and password values
' with the ones you use on your ISY
userName = "admin"
password = "<yourpassword>"
restReq.open "GET", url, false, userName, password
restReq.send
WScript.echo restReq.responseText

JSON object extract from big query database using app script

I have a big query table that has a JSON object as one of the field in the table. How can I extract the data from the JSON object using app script. The object itself is nested. It looks like this
{
"uid": "124551",
"subjects": [
{
"tid": 37,
"title": "Algebra",
"html_id": "algebra",
"selected": true
},
{
"tid": 214853,
"title": "Trigonometry",
"html_id": "trigonometry",
"selected": true
},
{
"tid": 38,
"title": "Geometry",
"html_id": "geometry",
"selected": true
}
],
"cellphone": "09178854579",
"educations": [
{
"index": 0,
"schoolname": "University of the Philippines - Los Baños",
"degree": "BS Mathematics",
"major": "Mathematics",
"eduFrom": "2009-05-31T16:00:00.000Z",
"eduTo": "2013-04-26T16:00:00.000Z",
"eduFromTs": 1243785600,
"eduToTs": 1366992000
}
],
"info": {
"os": "Windows",
"internet": "ADSL",
"browser": "Chrome",
"network": "Wireless",
"speed": "",
"timezone": "Asia/Hong_Kong"
}
}
I want to extract all school names from education field. Any ideas?
Working with JSON objects is similar to working with XML, except that parsing or encoding a JSON object is much easier.
Once this string is retrieved, simply call JSON.parse() on the string to get a native object representation.
var data = JSON.parse(json);
Browser.msgBox(data.info.os);
Other sample code is at https://developers.google.com/apps-script/advanced/bigquery#run_query