Can someone help me? Json bad string at line 20 - json

{
"suffix": {},
"chat": {
"Depreloid": "local"
},
"spy-mode": {
"Depreloid": true
},
"last-pm-interlocutor": {
"BLACKCAT12321": "Depreloid",
"Depreloid": "BLACKCAT12321"
},
"prefix": {
"Depreloid": "\u0026c[jfhkj] ",
"Sovaqa": "\u00266[jrqkrq] ",
"KorolSombra": "\u0026b [ljwljf] ",
"BLACKCAT12321": "\u0026b [test] ",
"Nikof2": "\u00262[Лfkwokfw] ",
"Yra": "\u00262[fkffkfjfj] ",
},
}
well, I tried to move brackets) in short, I want to fix the bad string error and that's it...

You need to remove:
{
"suffix": {},
"chat": {
"Depreloid": "local"
},
"spy-mode": {
"Depreloid": true
},
"last-pm-interlocutor": {
"BLACKCAT12321": "Depreloid",
"Depreloid": "BLACKCAT12321"
},
"prefix": {
"Depreloid": "\u0026c[jfhkj] ",
"Sovaqa": "\u00266[jrqkrq] ",
"KorolSombra": "\u0026b [ljwljf] ",
"BLACKCAT12321": "\u0026b [test] ",
"Nikof2": "\u00262[Лfkwokfw] ",
"Yra": "\u00262[fkffkfjfj] "
}
}
So basically the trailing comma after "Yra": "\u00262[fkffkfjfj] " needs to be removed and the trailing comma at the end of the enclosing object needs to be removed.

Related

JSON Parse: Expecting "EOF" got undefined error

Im trying to PARSE this JSON and getting this error Expecting "EOF" got undefined error, not sure not sure what I am missing in line 14.
example:
{
"plotOptions": {
"series": {
"dataLabels": {
"enabled": true
}
},
"column": {
"stacking": "percent",
"dataLabels": {
"format": "{point.percentage:.1f}%"
},
"tooltip": {
"pointFormat": "<span style="\ & quot;color: {
point.color
}\ & quot;
">●</span> {series.name}: <b>{point.y} ({point.percentage:.1f}%)</b><br>"
}
},
"bar": {}
},
"yAxis": {
"stackLabels": {
"enabled": true
},
"title": {}
},
"xAxis": {
"title": {}
},
"categorySort": "asc"
}
This issue is with string quoting for this attribute pointFormat:
I removed the back-slash, connected ampsand with "quot" and used single quote inside the double quote, then it becomes a valid JSON, see screenshot below

Get customschema data

I am new to this new world of programming with GAS, I have not programmed anything for a long time and the change of structure is a bit complicated to understand. I have an app-script that reads the data of the domain users and it works very well, but it doesn't bring me the customschema fields. I've searched quite a bit in the documentation, until I found something that seemed to work.
I created a function and tried to retrieve the fields I need and it works. What it does is look up a user and fetch the data.
Then I wanted to use that function but passing it the userkey of the user in question and then return one of the fields. But it stopped working, it only brought the normal data, but from the customschema, nothing.
My function is:
function LeeUser() {
var iuserEmail = "user#midominio.com";
var test = {
"name": {
"familyName": "",
"givenName": ""
},
"password": "",
"primaryEmail": "",
"orgUnitPath": "",
"emails":[{
"type": "work",
"address": "",
}],
"customSchemas": {
"Organizacion_Interna": {
"NombreFuncionario": "",
"FechaCaducidad": ""
}
},
};
try {
test = AdminDirectory.Users.get(iuserEmail,{"projection": "full"});
console.log(test.customSchemas.Organizacion_Interna.FechaCaducidad);
} catch (err) {
Logger.log('Failed with error %s', err.message);
}
}
But when I change
function LeeUser(userEmail) {
var iuserEmail = userEmail;
var test = {
"name": {
"familyName": "",
"givenName": ""
},
"password": "",
"primaryEmail": "",
"orgUnitPath": "",
"emails":[{
"type": "work",
"address": "",
}],
"customSchemas": {
"Organizacion_Interna": {
"NombreFuncionario": "",
"FechaCaducidad": ""
}
},
};
try {
test = AdminDirectory.Users.get(iuserEmail,{"projection": "full"});
return test.customSchemas.Organizacion_Interna.FechaCaducidad;
} catch (err) {
Logger.log('Failed with error %s', err.message);
}
}
It tells me that the field is not defined.
what's the problem?
Any suggestion
Thanks in advance.

Groovy Collect values from nested json arrays

I am trying to map a nested json into a flat file but have an issue referencing between different arrays.
I get it working for each array separately but can't figure out how to properly reference the parent ids to be included. I tried working with indexes and copying the event.id and event.lots.id on the pricings objects but that got really messy.
Maybe I am just on the wrong track or didn't have the right idea on how this might work.
Code
def body = message.getBody(String.class)
def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText(body)
def i_events = object.events
def i_lots = object.events.lots
def i_pricing = object.events.lots.pricings
def o_values = i_pricing.flatten().collect {"(" + "'" + i_events.collect{it.id}[0] + "'" + "," + "'" + i_lots.collect{it.id}[1] + "'" + "," + "'" + it.id + "'" + "," + "'" +it.name + "'" + ")" }.join(',')
//just using print for testing
println o_values
Result
('event_id1','[id A, id B]','p id1','TEST 1'),('event_id1','[id A, id B]','p id2','TEST 2')
Expected Result
('event_id1','id3','p id1','TEST 1'),('event_id1','id A','p id2','TEST 2')
Sample input
{
"events": [
{
"id": "event_id1",
"name": "Test Event 01",
"to": "2021-08-27T02:30:00.000Z",
"from": "2021-08-26T16:15:00.000Z",
"parkingTo": "2021-08-27T02:30:00.000Z",
"parkingFrom": "2021-08-26T14:15:00.000Z",
"landmarkId": "111",
"slug": "test-event1",
"live": true,
"lots": [
{
"id": "id1",
"name": "Lot 1",
"pricings": []
},
{
"id": "id2",
"name": "Lot 2",
"pricings": []
},
{
"id": "id3",
"name": "Lot3",
"pricings": [
{
"id": "p id1",
"name": "TEST 1"
}
]
}
]
},
{
"id": "event_id2",
"name": "Test Event 2",
"to": "2020-08-31T17:00:00.000Z",
"from": "2020-08-31T14:00:00.000Z",
"parkingTo": "2020-09-01T08:45:00.000Z",
"parkingFrom": "2020-08-31T12:45:00.000Z",
"landmarkId": "111",
"slug": "test-event2",
"live": true,
"lots": [
{
"id": "id A",
"name": "lot A",
"pricings": [
{
"id": "p id2",
"name": "TEST 2"
}
]
},
{
"id": "id B",
"name": "lot B",
"pricings": []
}
]
}
],
"meta": {
"total": 2,
"firstElement": 0,
"lastElement": 2
}
}
Something like this should work (it's hard to say, as your example input seems different to your expected output)
I added a quote method for if the values contain a ', you will need to think if you need this, and how you're going to escape things
def escape(String s) {
"'${s.replaceAll("'", "\\\\'")}'"
}
def output = new JsonSlurper().parseText(body).events.collectMany { event ->
event.lots.collectMany { lot ->
lot.pricings.collect { pricing ->
"(${escape(event.id)}, ${escape(lot.id)}, ${escape(pricing.id)}, ${escape(pricing.name)})"
}
}
}.join(',')

Replacing Slashes in JSON URL Data

I want to replace "\\" to "/" in productImage path, my code as below I used replace method but didn't work, waiting for your help thank you
const response = {
count: docs.length,
products: docs.map(doc => {
return {
name: doc.name,
price: doc.price,
productImage: doc.productImage,
_id: doc._id,
request: {
type: "GET",
url: url + "/products/" + doc._id
}
};
})
};
My JSON Output
{
"name": " Sample Product",
"price": 45,
"productImage": "uploads\\2018-05-02T09-12-59.937Zahmet.jpg",
"_id": "5ae9811be170eb0a78500088",
"request": {
"type": "GET",
"url": "http://localhost:3000/products/5ae9811be170eb0a78500088"
}
},
You can split that value by \\, you'll get an array, join that array with /
var obj = {
"name": " Sample Product",
"price": 45,
"productImage": "uploads\\2018-05-02T09-12-59.937Zahmet.jpg",
"_id": "5ae9811be170eb0a78500088",
"request": {
"type": "GET",
"url": "http://localhost:3000/products/5ae9811be170eb0a78500088"
}
}
obj.productImage = obj.productImage.split("\\").join("/");
console.log(obj)

indexing json with json value in elasticsearch

I am trying to index a document in elasticsearch. The json I have comes from the document being transformed from XML to JSON. It is valid JSON. Looks like this:
{
"shortcasename": {
"_attributes": {
"party1": "People",
"party2": "Johnson"
},
"_children": [
"People",
{
"connector": {
"_attributes": {
"normval": "v"
},
"_children": [
" v. "
]
}
},
"Johnson"
]
}
}
Elasitcsearch seems to have a problem with the shortcasename._children. The error I get is:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "failed to parse"
}
],
"type": "mapper_parsing_exception",
"reason": "failed to parse",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "mapper [shortcasename._children] of different type, current_type [string], merged_type [ObjectMapper]"
}
},
"status": 400
}
Is there a way to get the json to be indexed the way it is?
The JSON you have has a conflict with the _children field:
{
"shortcasename": {
"_attributes": {
"party1": "People",
"party2": "Johnson"
},
"_children": [
"People",
{
"connector": {
"_attributes": {
"normval": "v"
},
"_children": [
" v. "
]
}
},
"Johnson"
]
}
}
The top-level _children field is an array containing a mix of objects ({"connector": ...}) and strings ("People", "Johnson"). Elasticsearch doesn't support that, that's why it complains that it cannot merge string and Object