Incorrect JSON format - json

I am trying to construct a JSON formats follows but running into below error, what is wrong with the below format and how to fix it?
{
project_sha_list: [{
project: project1
sha: sha1
},
{
project: project2
sha: sha2
}
]
train: train1
}
ERROR:-
Error: Parse error on line 1:
{ project_sha_list: [{
--^
Expecting 'STRING', '}', got 'undefined'

JSON keys and string values must be in quotes like below, but if the value is integer,double,long then it should not be enclosed in quotes, and if you have multiple properties each property should end with , except last one
{
"project_sha_list": [
{
"project": "project1",
"sha": "sha1"
},
{
"project": "project2",
"sha": "sha2"
}
],
"train": "train1"
}

Your JSON should be:
{
"project_sha_list": [
{
"project": "project1",
"sha": "sha1"
},
{
"project": "project2",
"sha": "sha2"
}
],
"train": "train1"
}
You can validate it here
you keys and values both should be within "

Try this format:
{
"project_sha_list": [
{
"project": project1,
"sha": sha1
},
{
"project": project2,
"sha": sha2
}
],
"train": train1
}

The correct jain format is:
{
"project_sha_list": [
{ "project": "project1", "sha": "sha1" },
{ "project": "project2", "sha": "sha2" }
],
"train": "train1"
}

Related

jmespath :select json object element based on other (array) element in the object

I have this JSON
{
"srv_config": [{
"name": "db1",
"servers": ["srv1", "srv2"],
"prop": [{"source":"aa"},"destination":"bb"},{"source":"cc"},"destination":"cc"},]
}, {
"name": "db2",
"servers": ["srv2", "srv2"],
"prop": [{"source":"dd"},"destination":"dd"},{"source":"ee"},"destination":"ee"},]
}
]
}
I try to build a JMESPath expression to select the prop application in each object in the main array, but based on the existence of a string in the servers element.
To select all props, I can do:
*.props [*]
But how do I add condition that says "select only if srv1 is in servers list"?
You can use the contains function in order to filter based on a array containing something.
Given the query:
*[?contains(servers, `srv1`)].prop | [][]
This gives us:
[
{
"source": "aa",
"destination": "bb"
},
{
"source": "cc",
"destination": "cc"
}
]
Please mind that I am also using a bit of flattening here.
All this run towards a corrected version of you JSON:
{
"srv_config":[
{
"name":"db1",
"servers":[
"srv1",
"srv2"
],
"prop":[
{
"source":"aa",
"destination":"bb"
},
{
"source":"cc",
"destination":"cc"
}
]
},
{
"name":"db2",
"servers":[
"srv2",
"srv2"
],
"prop":[
{
"source":"dd",
"destination":"dd"
},
{
"source":"ee",
"destination":"ee"
}
]
}
]
}

How to save data in Json format in React-admin v3?

I created JsonInput, which sends a json object to the input SimpleForm, however, a modified version of it gets into the Data Provider.
that's what is sent to the input:
json: {
"FunctionalGroup": [
{
"uaIDref": [
"2104"
],
"_Name": "Текущие параметры",
"_ID": "33"
},
{
"uaIDref": [
"2100"
],
"_Name": "Текущие параметры пониженной точности",
"_ID": "34"
},
],
"_Name": "Прибор 1",
"_ID": "32"
}
that's what came to the server:
json: {
"FunctionalGroup": [
{
"uaIDref": [
"2104"
],
"_Name": "Текущие параметры",
"_ID": "33"
},
{
"uaIDref": [
"2100"
],
"_Name": "Текущие параметры пониженной точности",
"_ID": "34"
}
],
"FunctionalGroupIds": "",
"_Name": "Прибор 1",
"_ID": "32"
},
after a response from the server with this object, this is what came in the field:
json: {
FunctionalGroup: [
{
uaIDref: [
'2104'
]
},
{
uaIDref: [
'2100'
]
}
],
FunctionalGroupIds: ''
}
what kind of magic is this?
I did some tests. When I converted the object to a string, the correct json was sent to the server, however, in the field after the server responded, the modified object was displayed again.
I found out that the conversion is related to redux.js, but what exactly happens is not understood.
Please give any comments on this.
How can I make save json?

JSON - Backslashes in Network Path

I have a PHP api which returns this JSON:
{
"recrutee": {
"recrutee_nom": "Mustermann",
"recrutee_statut": "Extern",
"recrutee_id_iam": "APP764",
"recrutee_debut_de_contrat": "2018-08-30",
"recrutee_fin_de_contrat": "2018-11-29",
"recrutee_prenom": "Max"
},
"responsable": {
"responsable_nom": "Musterman",
"responsable_prenom": "Marc",
"responsable_tel": "66666666",
"responsable_service": "It",
"responsable_email": "example#example.com"
},
"acces_reseau": [{
"path": "\\Some\Network\Path"
}],
"option_pc": [
{
"autre": "Nfc Reader"
}, {
"option": "internet"
}, {
"option": "lecteurluxtrust"
}, {
"option": "scanner"
}, {
"option": "imprimante"
}, {
"option": "ecransupplementaire"
}, {
"option": "lectuercodebarres"
}
],
"demande_id": "5b54588d00772",
"lieu": "Luxembourg City"
}
The problem is with the network path is it needs to look like this:
\\\\Some\\Network\\Path
Since backslashes are used as an escape character the network path in my original json is incorrect.
Is there any programatically (not manual) way to get this result:
\\\\Some\\Network\\Path

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

Elasticsearch - completion suggester payload transforming, returns invalid JSON

I am trying to use the elasticsearch completion suggester. I have app_user objects, which come into my elasticsearch instance via a couchdb river.
This is the mapping I use:
{
"app_user" : {
"_all" : {"enabled" : true},
"_source" : {
"includes" : [
"_id",
"_rev",
"type",
"profile.callname",
"profile.fullname",
"email"
]
},
"properties" : {
"suggest" : { "type" : "completion",
"index_analyzer" : "simple",
"search_analyzer" : "simple",
"payloads" : true
}
},
"transform" : [
{"script": "ctx._source.suggest = ['input':[ctx._source.email, ctx._source.profile.fullname, ctx._source.profile.callname]]"},
{"script": "ctx._source.suggest.payload = ['_id': ctx._source['_id'], 'type': ctx._source['type'], '_rev': ctx._source['_rev']]"}
,
{"script": "ctx._source.suggest.payload << ['label': ctx._source.profile.fullname, 'text': ctx._source.email]"}
]
}
}
So I am trying to include the object ID and a display text in the payload.
When I view the generated document via http://localhost:9200/myindex/app_user/<someid>?pretty&_source_transform, everything seems OK:
{
"_index": "myindex",
"_type": "app_user",
"_id": "<someid>",
"found": true,
"_source": {
"_rev": "2-dcd7b9d456e205d3e9d859fdc2c6a688",
"_id": "<someid>",
"email": "joni#example.org",
"suggest": {
"input": [
"joni#example.org",
...
],
"output": "joni surname - joni#example.org",
"payload": {
"_id": "<someid>",
"type": "app_user",
"_rev": "2-dcd7b9d456e205d3e9d859fdc2c6a688",
"label": "joni surname",
"text": "joni#example.org"
}
},
"type": "app_user",
"profile": {
"callname": "",
"fullname": "joni surname"
}
}
}
However, when I try to get the document via _suggest, elasticsearch API somehow breaks the JSON object payload:
curl -XGET "http://localhost:9200/myindex/_suggest" -d '{
"all-suggest": {
"text": "joni",
"completion": {
"field": "suggest"
}
}
}'
results in
{"_shards":{"total":5,"successful":5,"failed":0},"all-suggest":[{"text":"joni","offset":0,"length":5,"options":[{"text":"joni surname - joni#example.org","score":1.0,"payload"::)
�_id`<someid>�typeIapp_user�_reva2-dcd7b9d456e205d3e9d859fdc2c6a688�label�joni surname�textSjoni#example.org�}]}]}
which is definitely no valid JSON.. Any ideas?
This is actually a bug in elasticsearch. It was reported and acknowledged here and should be fixed shortly.