What is wrong with the following JSON data - json

JSON -
[
{
"pagename":"1",
"url":"sadadsad",
"group":"ad"
},
{
"pagename":"2",
"url":"sasdsad",
"group":"eng"
},
{
"pagename":"3",
"url":"thfgv",
"group":"pd"
},
{
"pagename":"4",
"url":"tuyi",
"group":"pd"
},
{
"pagename":"5",
"url":"popop",
"group":"pd"
}
]
Error: Parse error on line 2:
... { pagename:"1",
---------------------^
Expecting 'STRING', '}'
Edit: With this rectified JSON data when I am printing the length, it's coming out to be 486, looks like some stray characters are getting added, how can I resolve that.

You need to put pagename and all other var names in quotes also
[
{
"pagename":"1",
"url":"sadadsad",
"group":"ad"
},
If you want to know why the quotes are needed, have a look at this answer: in JSON, Why is each name quoted?

The correct format is as follows
[
{
"pagename":"1",
"url":"sadadsad",
"group":"ad"
},
{
"pagename":"2",
"url":"sasdsad",
"group":"eng"
},
{
"pagename":"3",
"url":"thfgv",
"group":"pd"
},
{
"pagename":"4",
"url":"tuyi",
"group":"pd"
},
{
"pagename":"5",
"url":"popop",
"group":"pd"
}
]
Be sure to verify your JSON here. The errors are highlighted in black.

Related

Unexpected Token error in my JSON when I try to read it in Angular

I Have this JSON file that I have validated
[
{
"CodigoProyecto": "ABREA242"
},
{
"CodigoProyecto": "ABSUMTOT"
},
{
"CodigoProyecto": "AETXA521"
},
{
"CodigoProyecto": "ALGOH035"
},
{
"CodigoProyecto": "AMEZA582"
},
{
"CodigoProyecto": "ANACA001"
},
...
}
]
In my component, I have this
import proyectosEnSharePoint from './carpetasSharePoint.json';
proyectosEnSharePoint: { codigoProyecto: string }[] = proyectosEnSharePoint;
But when I run I get this error
Module parse failed: Unexpected token "�" (0xFFFD) in JSON at position 0 while parsing near "��[\u0000\r\u0000\n\u0000 \u0000 \u0000 \u0000 \u0000{\u0000\r\u0000..."
Any idea, please?
Thanks
I Had UTF-16 now solved changing it to UTF-8

How to replace double quotes in a json string in Golang?

I have a problem parsing a string object to JSON with Golang.
there are double quotes in some fields values.
I'm trying to use a regex pattern but it doesn't work for me, I'm doing the conversion from bigquery which is based on the Golang code but it doesn't work for me.
{
"Responses": [],
"SessionParameters(Updated)": {
"counter-no-match-nombre": "($session.params.counter-no-match, 1)",
"message": "Hello."
},
"SystemFunctionResults": {
"SystemFunctionErrors": [
{
"Message": "Wrong type of argument for function "NONE", expected 1th argument to be one of type: ["number"]."
}
]
}
}
here a example
([:[,{]\s*)"(.?)"(?=\s[:,]}])
Test regex
SELECT
REGEXP_REPLACE('{
"obj1": "value is "test" of test, \"obj1\" val",
"result": "your result is "out" in our website",
"info": {
"x": [
{
"desc": "shjjfdsajfjkfsdkf, "sfsdfsdfdsf" fjkdfgjkfd."
}
]
}
}','([:\\[,{]\\s*)"(.*?)"(?:\\s*[:,\\]}])','NONE')
AS json_data;
I would appreciate your help, thanks

How to select JSON array (JSON substring) in JasperReport with JSONQL?

I want to create a report using Jaspersoft Studio with a json file as datasource. I want to select some fields from this json and also a substring of the original json. This should be done by jsonql.
First, an example with the "JSON language" in JasperSoftStudio:
gives the following result:
This is exactly what I want to have, the delivery note number as a field, and the barcodes as an array of objects / json substring.
What I am not able to do is, to achieve this with jsonql. The following query
gives the result
The following json was used for this example
{
"tour": {
"shipments": [
{
"containers": [
{
"boxes": [
{
"customerModule": "DEFG",
"deliveryDateTime": "2022-04-25 11:49:24.834000",
"boxNumber": 2
},
{
"customerModule": "ABCD",
"deliveryDateTime": "2022-04-25 11:50:24.810000",
"boxNumber": 1
}
],
"licensePlate": "123"
}
],
"deliveryNoteNumber": "6785000",
"barcodes": [
{
"content": "barcode_01_04"
},
{
"content": "barcode_03_04"
},
{
"content": "barcode_04_04"
}
]
},
{
"containers": [
{
"boxes": [
{
"customerModule": "ZXYV",
"deliveryDateTime": "2022-04-25 11:51:24.834000",
"boxNumber": 1
},
{
"customerModule": "UHGI",
"deliveryDateTime": "2022-04-25 11:52:24.834000",
"boxNumber": 2
}
],
"licensePlate": "987"
}
],
"deliveryNoteNumber": "6785001",
"barcodes": [
{
"content": "Barcode_01_04"
},
{
"content": "Barcode_02_04"
},
{
"content": "Barcode_04_04"
}
]
}
],
"handlingDateTime": "2022-04-25 11:50:24.883000"
}
I tried to use this documentation, but I could not get it working.
The JSONQL data source doesn't properly convert arrays to Strings for some reason.
What you can do is change the barcodes field from java.lang.String to java.lang.Object. You can do that by clicking Edit in the Fields tab and changing the Class Type for the field.
With java.lang.Object as field type, the field value will be the underlying JSON (Jackson) model array object. You can do $F{barcodes}.toString() if you need to explicitly convert it to a String in an expression.

Validate nested response body rest assured

I know that there is a lot of information regarding validations in rest assure but unfortunately I am not able to find exactly the solution to my issue.
I am training to validate the response of the following JSON:
{
"A":[
{
"B":[
{
"C":"c",
"D":"d"
}
],
"E":[
{
"F":[
{
"G":"g1"
}
]
},
{
"F":[
{
"G":"g2"
}
],
},
{
"F":[]
}
]
}
],
"H": "h"
}
with the following code:
response.body("A.E.F.G", hasItems(expectedValues.get(G).toArray(new String[0])))
expectedValues.get(G) return a list of g1 and g2.
the ERROR that I get is:
JSON path A.E.F.G doesn't match.
Expected: an array containing ["g1", "g2"]
Actual: [[[g1], [g2], []]]
How can I get that done?
That solve the problem:
response.body("A.E.F.G.flatten()", hasItems(expectedValues.get(G).toArray(new String[0])))

how to iterating through json data in python?

I have a json output like below,
{
"took":3,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},
"hits":{"total":2,"max_score":1.0,
"hits":
[
{
"_index":"management",
"_type":"",
"_id":"/home/myfld1/myid1",
"_score":1.0,
"_source" :
{
"newslides": "User Mgmt1 ",
"metaData":
{
"fileName": "file1",
}
}
},
{
"_index":"management",
"_type":"",
"_id":"/home/myfld3/myid3",
"_score":1.0,
"_source" :
{
"newslides": "User mgmt2 ",
"metaData":
{
"fileName": "file2",
}
}
}
]
}
}
I am trying to get the "fileName" field from the above json. I have tried like this,
for filenames in response["hits"]["hits"][0]["_source"]["newslides"]["metaData"]:
filearray.append(filenames["fileName"])
But i am getting one error like below,
for filenames in response["hits"]["hits"][0]["_source"]["newslides"]["metaData"]:
TypeError: string indices must be integers
Please help me to get that file name.
It is simply a dictionary with some lists and other dictionaries in it. Just be careful and go through the elements iteratively:
filearray = []
for x in response["hits"]["hits"]:
filearray.append(x["_source"]["metaData"]["fileName"])
or in one line:
filearray = [x["_source"]["metaData"]["fileName"] for x in response["hits"]["hits"]]