Have a question about ElasticSearch searching. F.e. I performed a search with query "EPS 100" and ES returned 3 documents with sorting by 1) _score 2) discount:
[
{
"_index": "index",
"_type": "default",
"_id": "23611",
"_score": 4027.2395,
"_source": {
"name": "ETNA EPS 100 - 20 x 600 x 1200"
},
"sort": [
4027.2395, <--- _score
0 <---- Discount
]
},
{
"_index": "index",
"_type": "default",
"_id": "23610",
"_score": 3950.8713,
"_source": {
"name": "ETNA EPS 80 - 100 x 600 x 1200 mm"
},
"sort": [
3950.8713, <--- _score
0 <--- Discount
]
},
{
"_index": "index",
"_type": "default",
"_id": "23602",
"_score": 3872.0818,
"_source": {
"name": "ETNA EPS 50 - 100 x 600 x 1200 mm"
},
"sort": [
3872.0818, <--- _score
3.72 <--- Discount
]
}
]
The question is how should I perform my search to:
Firstly, find exact match by my search query
Secondly, if exact match is not found, the nearest result with discount should appear next
In given JSON I should see the following results:
ETNA EPS 100 - 20 x 600 x 1200 (Exact match by "EPS 100")
ETNA EPS 50 - 100 x 600 x 1200 mm (because discount present)
ETNA EPS 80 - 100 x 600 x 1200 mm
EDIT 1:
My query:
{
"query": {
"function_score": {
"query": {
"boosting": {
"positive": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"term": {
"code": {
"value": "eps 100",
"boost": 200
}
}
},
{
"multi_match": {
"fields": [
"name",
"name.folded"
],
"query": "eps 100",
"type": "cross_fields",
"operator": "and",
"boost": 2
}
},
{
"multi_match": {
"fields": [
"name.search_folded"
],
"query": "eps 100",
"type": "cross_fields",
"operator": "and",
"boost": 500
}
},
{
"match_phrase_prefix": {
"name.search_folded": {
"query": "eps 100"
}
}
},
{
"match_phrase_prefix": {
"name.folded": {
"query": "eps 100"
}
}
}
],
"filter": [
{
"term": {
"enabled": {
"value": true,
"boost": 1
}
}
}
]
}
}
}
}
}
},
"sort": {
"_score": {
"order": "desc"
},
"discount": {
"order": "desc",
"missing": "_last",
"unmapped_type": "double"
}
}
}
Mapping:
{
"state": "open",
"settings": {
"index": {
"mapping": {
"total_fields": {
"limit": "2000"
}
},
"number_of_shards": "5",
"provided_name": "name",
"creation_date": "1664261140456",
"analysis": {
"filter": {
"lithuanian_stop": {
"type": "stop",
"stopwords": "_lithuanian_"
},
"lithuanian_stemmer": {
"type": "stemmer",
"language": "lithuanian"
}
},
"char_filter": {
"lithuanian_char_filter": {
"type": "mapping",
"mappings": [
"a => 10",
"A => 10",
"ą => 11",
"Ą => 11",
"b => 12",
"B => 12",
"c => 13",
"C => 13",
"č => 14",
"Č => 14",
"d => 15",
"D => 15",
"e => 16",
"E => 16",
"ę => 17",
"Ę => 17",
"ė => 18",
"Ė => 18",
"f => 18",
"F => 18",
"g => 19",
"G => 19",
"h => 20",
"H => 20",
"i => 21",
"I => 21",
"į => 22",
"Į => 22",
"y => 23",
"Y => 23",
"j => 24",
"J => 24",
"k => 25",
"K => 25",
"l => 26",
"L => 26",
"m => 27",
"M => 27",
"n => 28",
"N => 28",
"o => 29",
"O => 29",
"p => 30",
"P => 30",
"r => 31",
"R => 31",
"s => 32",
"S => 32",
"š => 33",
"Š => 33",
"t => 34",
"T => 34",
"u => 35",
"U => 35",
"ų => 36",
"Ų => 36",
"ū => 37",
"Ū => 37",
"v => 38",
"V => 38",
"z => 39",
"Z => 39",
"ž => 40",
"Ž => 40"
]
}
},
"normalizer": {
"lithuanian_sort_normalizer": {
"char_filter": [
"lithuanian_char_filter"
]
}
},
"analyzer": {
"search_asciifolding": {
"filter": [
"lowercase",
"asciifolding"
],
"tokenizer": "standard"
},
"lithianian_asciifolding": {
"filter": [
"lowercase",
"asciifolding",
"lithuanian_stop",
"lithuanian_stemmer"
],
"tokenizer": "standard"
}
}
},
"number_of_replicas": "1",
"uuid": "uuid",
"version": {
"created": "6040399"
}
}
},
"mappings": {
"default": {
"dynamic_templates": [
{
"name": {
"mapping": {
"analyzer": "lithuanian",
"fields": {
"search_folded": {
"analyzer": "search_asciifolding",
"type": "text"
},
"keyword": {
"type": "keyword"
},
"folded": {
"analyzer": "lithianian_asciifolding",
"type": "text"
}
},
"type": "text"
},
"match": "name"
}
},
{
"discount_attribute": {
"mapping": {
"type": "double"
},
"match": "discount"
}
}
]
}
}
}
Maybe the query I propose is not the silver bullet but it can help you get the result you want. I used the field value factor to boost the docs with the "discount" field. Note that there are two match clauses, the first one is to ensure exact match and I added a high boost to ensure exact docs at the top even if the discount field is zero. The second is just to recover the remaining documents.
{
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"match": {
"name": {
"query": "EPS 100", >> boost for exactly match
"boost": 100,
"operator": "and"
}
}
},
{
"match": {
"name": {
"query": "EPS 100" >> return all doc with term eps
}
}
}
]
}
},
"functions": [
{
"field_value_factor": {
"field": "discount", >> boost for doc with discount
"factor": 1.2,
"modifier": "none"
}
}
],
"score_mode": "multiply",
"boost_mode": "sum"
}
}
}
Related
Json body looks like this:
{
"access_key": "",
"erid": "",
"ch_sms": {
"messages": [
{
"urlsh": false,
"sp": "123",
"vp": 20,
"heid": 1,
"teid": ,
"peid": ,
"tmid": 4,
"msg": {
"txt": "hello"
},
"da": [
{
"number": "97278",
"cc": "IN",
"uid": "uid1",
"tags": [
"key",
"Value"
]
}
]
}
],
"metadata": {
"chver": "1.0",
"cburl": "",
"heid": 1,
"teid": ,
"peid": ,
"tmid": 4,
"Oa": "",
"flash": false,
"tags": [
"key",
"tag1"
]
}
}
}
We need to add multiple "da" sections based on user input. For example if I give input from a CSV file as 3 then "da" section will repeat 3 times and it will look like as follow:
{
"access_key": "",
"erid": "",
"ch_sms": {
"messages": [
{
"urlsh": false,
"sp": "123",
"vp": 20,
"heid": 1,
"teid": ,
"peid": ,
"tmid": 4,
"msg": {
"txt": "hello"
},
"da": [
{
"number": "97278",
"cc": "IN",
"uid": "uid1",
"tags": [
"key",
"Value"
]
},
{
"number": "97278",
"cc": "IN",
"uid": "uid1",
"tags": [
"key",
"Value"
]
},
{
"number": "97278",
"cc": "IN",
"uid": "uid1",
"tags": [
"key",
"Value"
]
}
]
}
],
"metadata": {
"chver": "1.0",
"cburl": "",
"heid": 1,
"teid": ,
"peid": ,
"tmid": 4,
"Oa": "",
"flash": false,
"tags": [
"key",
"tag1"
]
}
}
}
You can try this,
import org.json.simple.JSONObject
JSONObject data = new JSONObject()
data.put("number", "97278")
data.put("cc", "IN")
data.put("uid", "uid1")
data.put("tags", ["key","Value"])
int da = Integer.parseInt(vars.get("da"))
ArrayList<Object> listData = new ArrayList<Object>()
for(int i=0; i < da; i++)
{
listData.add(data.toString())
}
log.info("da: " + listData )
Result log:
da: [{"cc":"IN","number":"97278","uid":"uid1","tags":["key","Value"]}, {"cc":"IN","number":"97278","uid":"uid1","tags":["key","Value"]}, {"cc":"IN","number":"97278","uid":"uid1","tags":["key","Value"]}]
How can I get the email address from the feed provided by HubSpot below:
{
"contacts": [
{
"addedAt": 1390574181854,
"vid": 204727,
"canonical-vid": 204727,
"merged-vids": [
],
"portal-id": 62515,
"is-contact": true,
"profile-token": "AO_T-mMusl38dq-ff-Lms9BvB5nWgFb7sFrDU98e-3CBdnB7G2qCt1pMEHC9zmqSfOkeq2on6Dz72P-iLoGjEXfLuWfvZRWBpkB-C9Enw6SZ-ZASg57snQun5f32ISDfLOiK7BYDL0l2",
"profile-url": "https://app.hubspot.com/contacts/62515/lists/public/contact/_AO_T-mMusl38dq-ff-Lms9BvB5nWgFb7sFrDU98e-3CBdnB7G2qCt1pMEHC9zmqSfOkeq2on6Dz72P-iLoGjEXfLuWfvZRWBpkB-C9Enw6SZ-ZASg57snQun5f32ISDfLOiK7BYDL0l2/",
"properties": {
"firstname": {
"value": "Bob"
},
"lastmodifieddate": {
"value": "1483461406481"
},
"company": {
"value": ""
},
"lastname": {
"value": "Record"
}
},
"form-submissions": [
],
"identity-profiles": [
{
"vid": 204727,
"saved-at-timestamp": 1476768116149,
"deleted-changed-timestamp": 0,
"identities": [
{
"type": "LEAD_GUID",
"value": "f9d728f1-dff1-49b0-9caa-247dbdf5b8b7",
"timestamp": 1390574181878
},
{
"type": "EMAIL",
"value": "mgnew-email#hubspot.com",
"timestamp": 1476768116137
}
]
}
],
"merge-audits": [
]
},
{
"addedAt": 1392643921079,
"vid": 207303,
"canonical-vid": 207303,
"merged-vids": [
],
"portal-id": 62515,
"is-contact": true,
"profile-token": "AO_T-mPMwvuZG_QTNH28c_MbhSyNRuuTNw9I7zJAaMFjOqL9HKlH9uBteqHAiTRUWVAPTThuU-Fmy7IemUNUvdtYpLrsll6nw47qnu7ACiSHFR6qZP1tDVZFpxueESKiKUIIvRjGzt8P",
"profile-url": "https://app.hubspot.com/contacts/62515/lists/public/contact/_AO_T-mPMwvuZG_QTNH28c_MbhSyNRuuTNw9I7zJAaMFjOqL9HKlH9uBteqHAiTRUWVAPTThuU-Fmy7IemUNUvdtYpLrsll6nw47qnu7ACiSHFR6qZP1tDVZFpxueESKiKUIIvRjGzt8P/",
"properties": {
"firstname": {
"value": "Ff_FirstName_0"
},
"lastmodifieddate": {
"value": "1479148429488"
},
"lastname": {
"value": "Ff_LastName_0"
}
},
"form-submissions": [
],
"identity-profiles": [
{
"vid": 207303,
"saved-at-timestamp": 1392643921090,
"deleted-changed-timestamp": 0,
"identities": [
{
"type": "EMAIL",
"value": "email_0be34aebe5#abctest.com",
"timestamp": 1392643921079
},
{
"type": "LEAD_GUID",
"value": "058378c6-9513-43e1-a13a-43a98d47aa22",
"timestamp": 1392643921082
}
]
}
],
"merge-audits": [
]
}
],
"has-more": true,
"vid-offset": 207303
}
I am able to get the other fields such as first name and last name using the snipped below (I am using WordPress, so the exact code is replicated using: wp_remote_get($url, $args) ) and inside the foreach I have the following code:
foreach($y->contacts as $z) {
echo "First Name: " . $z->properties->firstname->value . '<br>';
echo "Last Name: " . $z->properties->lastname->value . '<br>';
}
Hi you can do it this way using json_decode with true as second parameter to return a associative array:
php:
<?php
$str = '{
"contacts": [
{
"addedAt": 1390574181854,
"vid": 204727,
"canonical-vid": 204727,
"merged-vids": [
],
"portal-id": 62515,
"is-contact": true,
"profile-token": "AO_T-mMusl38dq-ff-Lms9BvB5nWgFb7sFrDU98e-3CBdnB7G2qCt1pMEHC9zmqSfOkeq2on6Dz72P-iLoGjEXfLuWfvZRWBpkB-C9Enw6SZ-ZASg57snQun5f32ISDfLOiK7BYDL0l2",
"profile-url": "https://app.hubspot.com/contacts/62515/lists/public/contact/_AO_T-mMusl38dq-ff-Lms9BvB5nWgFb7sFrDU98e-3CBdnB7G2qCt1pMEHC9zmqSfOkeq2on6Dz72P-iLoGjEXfLuWfvZRWBpkB-C9Enw6SZ-ZASg57snQun5f32ISDfLOiK7BYDL0l2/",
"properties": {
"firstname": {
"value": "Bob"
},
"lastmodifieddate": {
"value": "1483461406481"
},
"company": {
"value": ""
},
"lastname": {
"value": "Record"
}
},
"form-submissions": [
],
"identity-profiles": [
{
"vid": 204727,
"saved-at-timestamp": 1476768116149,
"deleted-changed-timestamp": 0,
"identities": [
{
"type": "LEAD_GUID",
"value": "f9d728f1-dff1-49b0-9caa-247dbdf5b8b7",
"timestamp": 1390574181878
},
{
"type": "EMAIL",
"value": "mgnew-email#hubspot.com",
"timestamp": 1476768116137
}
]
}
],
"merge-audits": [
]
},
{
"addedAt": 1392643921079,
"vid": 207303,
"canonical-vid": 207303,
"merged-vids": [
],
"portal-id": 62515,
"is-contact": true,
"profile-token": "AO_T-mPMwvuZG_QTNH28c_MbhSyNRuuTNw9I7zJAaMFjOqL9HKlH9uBteqHAiTRUWVAPTThuU-Fmy7IemUNUvdtYpLrsll6nw47qnu7ACiSHFR6qZP1tDVZFpxueESKiKUIIvRjGzt8P",
"profile-url": "https://app.hubspot.com/contacts/62515/lists/public/contact/_AO_T-mPMwvuZG_QTNH28c_MbhSyNRuuTNw9I7zJAaMFjOqL9HKlH9uBteqHAiTRUWVAPTThuU-Fmy7IemUNUvdtYpLrsll6nw47qnu7ACiSHFR6qZP1tDVZFpxueESKiKUIIvRjGzt8P/",
"properties": {
"firstname": {
"value": "Ff_FirstName_0"
},
"lastmodifieddate": {
"value": "1479148429488"
},
"lastname": {
"value": "Ff_LastName_0"
}
},
"form-submissions": [
],
"identity-profiles": [
{
"vid": 207303,
"saved-at-timestamp": 1392643921090,
"deleted-changed-timestamp": 0,
"identities": [
{
"type": "EMAIL",
"value": "email_0be34aebe5#abctest.com",
"timestamp": 1392643921079
},
{
"type": "LEAD_GUID",
"value": "058378c6-9513-43e1-a13a-43a98d47aa22",
"timestamp": 1392643921082
}
]
}
],
"merge-audits": [
]
}
],
"has-more": true,
"vid-offset": 207303
}';
$arr_json = json_decode($str,true);
foreach($arr_json["contacts"] as $key=>$value){
foreach($value["identity-profiles"] as $key2 => $item){
foreach($item["identities"] as $key3 => $sub){
if($sub["type"] == "EMAIL"){
echo "\n";
echo $sub["value"];
}
}
}
//echo $value["value"];
};
?>
you can try the code here http://sandbox.onlinephpfunctions.com/
Hope it helps
Thank you everybody for shedding some light, I eventually managed to get to the answer and here is my rough attempt (it's based on WordPress's $response = wp_remote_get( $url, $args ); ):
if( !is_wp_error( $response ) ) {
$response_body = json_decode($response['body']);
$decoded_response_body = json_decode( json_encode($response_body) );
if( isset($decoded_response_body->contacts) ) {
foreach( $decoded_response_body->contacts as $contact) {
// get user details
$fist_name = $contact->properties->firstname->value;
$last_name = $contact->properties->lastname->value;
$identities = $contact->{'identity-profiles'}[0]->identities;
foreach ( $identities as $key => $value ){
if ( strtolower($value->type) === 'email' ){
$contact_email = $value->value;
}
}
}
}
}
I am new to python, using python3. I have json data like:
{
"message": {
"count": 46,
"limit": 1000,
"schools": [
{
"class": "1",
"class_id": "1c8***",
"charges": [
{
"cost": 10,
"breakdown": [
{
"books": "1",
"unitQuantity": "10"
}
]
}
],
"area": "maccau"
},
{
"class": "2",
"class_id": "1c3***",
"charges": [
{
"cost": 100,
"breakdown": [
{
"books": "1",
"unitQuantity": "100"
}
]
}
],
"area": "maccau"
},
{
"class": "1",
"class_id": "1c3***",
"charges": [
{
"cost": 10,
"breakdown": [
{
"books": "1",
"unitQuantity": "10"
}
]
}
],
"area": "maccau"
},
{
"class": "2",
"class_id": "1c8***",
"charges": [
{
"cost": 50,
"breakdown": [
{
"books": "1",
"unitQuantity": "50"
}
]
}
],
"area": "maccau"
}
],
"url": {
"link": "/"
}
}
}
I was able to use json.loads to load data and I am trying to get results like:
class Cost
1 20
2 150
I tried converting json to a dictionary:
item_dict = json.load(json_data)
Tried to get data out using for loop and checking if class = 1 and then summing up the cost. But I feel like that is not the best approach. Can someone please tell me what would be the best way of doing this?
This is sort of a follow up question to this. I want to use 2 parameters in my assistant command. When I used only 1 parameter for a command, code worked flawlessly. However, when I added a second parameter to query pattern, the pattern was never detected. I have pasted my actions json file below. What have I missed?
{
"manifest": {
"displayName": "Start Test",
"invocationName": "Start Test",
"category": "PRODUCTIVITY"
},
"actions": [
{
"name": "com.example.actions.StartTest",
"availability": {
"deviceClasses": [
{
"assistantSdkDevice": {}
}
]
},
"intent": {
"name": "com.example.intents.StartTest",
"parameters": [
{
"name": "testname",
"type" : "TestSchema"
},
{
"name": "machinename",
"type" : "MachineSchema"
}
],
"trigger": {
"queryPatterns": [
"prepare ($TestSchema:testname) on ($MachineSchema:machinename)",
"start ($TestSchema:testname) on ($MachineSchema:machinename)",
"launch ($TestSchema:testname) on ($MachineSchema:machinename)"
]
}
},
"fulfillment": {
"staticFulfillment": {
"templatedResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Preparing to start test $testname on $machinename"
}
},
{
"deviceExecution": {
"command": "com.example.commands.StartTest",
"params": {
"testname": "$testname",
"machinename": "$machinename"
}
}
}
]
}
}
}
}
],
"types": [
{
"name": "$TestSchema",
"entities": [
{
"key": "BURN IN",
"synonyms": [
"burnin",
"burn in",
"burning",
"button"
]
},
{
"key": "WINTHRAX",
"synonyms": [
"when thanks",
"print tracks",
"fintrax",
"win tracks",
"winter sucks"
]
},
{
"key": "REBOOTER",
"synonyms": [
"reporter",
"repeat here",
"reboot"
]
},
{
"key": "SLEEPER",
"synonyms": [
"sleeper",
"sleep here",
"slipper"
]
},
{
"key": "IOMONKEY",
"synonyms": [
"are you monkey",
"I O monkey",
"I am monkey"
]
},
{
"key": "DISKERCISE",
"synonyms": [
"discus size",
"discuss I",
"Tisca size",
"Kiska size",
"discuss Eyes"
]
},
{
"key": "MFCJUNI",
"synonyms": [
"M F C Juni",
"MFC tunie",
"MFC tune",
"MFC Tu Ne"
]
},
{
"key": "SD STRESS",
"synonyms": [
"S D Stress",
"H D Stress",
"SD stress",
"HD stress",
"is distress",
"s distress",
"sdstress",
"SPSS",
"has De stress",
"FB status",
"HD stores",
"St stress"
]
},
{
"key": "POUNDIT",
"synonyms": [
"pound it",
"pundit",
"found it",
"foundit",
"pound rate",
"founded"
]
}
]
},
{
"name": "$MachineSchema",
"entities":[
{
"key": "HP LANE",
"synonyms": [
"HP lane",
"hp lane",
"hp line",
"h plane",
"hplane",
"hp name",
"HP rain",
"hp rain",
"HP name"
]
},
{
"key": "TPC-1001",
"synonyms": [
"tpc1001",
"tpc one thousand one",
"tpc 1001",
"tpc one thousand 1"
]
},
{
"key": "TPC-1002",
"synonyms": [
"tpc1002",
"tpc one thousand two",
"tpc 1002",
"tpc one thousand 2"
]
},
{
"key": "TPC-1003",
"synonyms": [
"tpc1003",
"tpc one thousand three",
"tpc 1003",
"tpc one thousand 3"
]
}
]
}
]
}
(Extracted answer from comments for higher visibility)
Do you need the parameters in parenthesis? It should be fine to have it without parenthesis, or adding a ? at the end will make it a wild card.
I am currently trying to setup a continuous integration system using VSTS and have run into a bit of a snag. As part of the release process I need to update a specific object value in a JSON file depending on the environment. The only tools it seems I have at my disposal that might get this done in the VSTS environment is PowerShell.
I've done quite a bit of research and have not been able to figure out how exactly this can be done. I found this question and answer here on Stack Overflow "How do I update JSON file using PowerShell" but executing the script provided in the answer changes the structure of the JSON file substantially and adds quite a bit of what looks like PowerShell metadata.
Ideally, I would like to take an existing JSON file that gets deployed and update the value of the connectionString property in the example JSON below.
{
"policies": {
"Framework.DataContext": {
"connectionString": "Server=ServerName;Database=DateBaseName;Integrated Security=sspi;"
}
}
}
Does anyone have any advice on how to accomplish this? So far I have tried running the following script but it throws an "The property 'connectionString' cannot be found on this object. Verify that the property exists and can be set." exception. I have verified that the object traversal is correct and the connectionString property exists.
$pathToJson = "D:\Path\To\JSON\file.json"
$a = Get-Content $pathToJson | ConvertFrom-Json
$a.policies.'Framework.DataContext'.connectionString = "Server=ServerName;Database=DateBaseName;Integrated Security=sspi;"
$a | ConvertTo-Json | set-content $pathToJson
The full contents of file.json are as follows
{
"log": {
"level": 0,
"file": "c:\\temp\\simport.log",
"formats": {
"error": null,
"start": null,
"requestBegin": null,
"requestWork": "",
"requestError": null,
"requestEnd": null,
"stop": null
},
"eventLog": {
"name": "Application"
}
},
"diagnostic": {
"stackTrace": false
},
"api": {
"simport": true
},
"roles": {
"0": "Anonymous",
"1": "Administrator",
"2": "Participant",
"3": "Facilitator"
},
"pathType": {
"area": 1,
"region": 2,
"session": 3,
"team": 4
},
"scenarios": {
"default": {
"default": true,
"initState": "Init",
"rounds": [
{
"name": "round1",
"displayName": "R1",
"beginTime": 1,
"endTime": 3
},
{
"name": "round2",
"displayName": "R2",
"beginTime": 4,
"endTime": 6
},
{
"name": "round3",
"displayName": "R3",
"beginTime": 7,
"endTime": 9
},
{
"name": "round4",
"displayName": "R4",
"beginTime": 10,
"endTime": 12
}
]
}
},
"simportQueries": {
"package": "bin/trc.simport3.zip"
},
"customQueries": {
"package": "app/config/custom-queries.zip",
"parameters": {
}
},
"audit": {
"Path.Create": true,
"Path.Delete": true,
"Team.Create": true,
"Team.Update": true,
"Team.Delete": true,
"SimportData.SaveValues": true
},
"tasks": {
"task1": {
"state": "",
"required": "",
"completed": "C:Task1Status:+0"
}
},
"feedback": {
"welcome": {
"text": {
"": "en-us",
"en-us": "Welcome"
}
}
},
"contentCategories": {
"demo1": {
"round": 1
}
},
"policies": {
"Simport.Web.Module": {
"fileMask": ".aspx,.asmx",
"deny": {
"statusCode": 404,
"statusDescription": "Not found",
"location": [
"/{0,1}app/config/(.*\\.json)$",
"/{0,1}app/config/(.*\\.xml)$",
"/{0,1}app/config/(.*\\.zip)$",
"/{0,1}app/config/(.*\\.xlsx)$"
]
},
"formDataContentType": [ "application/x-www-form-urlencoded" ]
},
"Framework.DataContext": {
"connectionString": "Server=(local);Database=Simport3;Integrated Security=sspi;",
"commandTimeout": 30
},
"Simport.Security": {
"passwordEncryption": "",
"passwordSalt": "",
"passwordPolicy": {
"disabled": true,
"min": 8,
"max": 100,
"rules": [
{ "id": "digit", "pattern": "\\d+", "flags": "i" },
{ "id": "letter", "pattern": "\\w+", "flags": "i" },
{ "id": "upper", "pattern": "[A-Z]+" },
{ "id": "lower", "pattern": "[a-z]+" },
{ "id": "special", "pattern": "[\\!##\\$_~]+", "flags": "i" },
{ "id": "prohibited", "pattern": "[\\\\/'\"\\?\\^&\\+\\-\\*\\%\\:;,\\.]+", "flags": "gi", "match": false }
]
}
},
"Simport.PackageDefinition": {
"path": "~/app/config/manifest.xml"
},
"Security.SignIn": {
"result": {
"default": "u,p,p.props,t"
},
"claims": [
[ "userId", "firstName", "lastName" ]
]
},
"Security.GetContext": {
"result": {
"default": "u,p,p.props,pr,t"
}
},
"Security.ChangePassword": {
"allowedRoles": [ 1, 2, 3 ]
},
"Security.ResetPassword": {
"allowedRoles": [ 1, 2 ]
},
"Security.Register": {
"allowedRoles": [ 0 ],
"!pathType-0": 4,
"!roleId-0": 2
},
"Path.Create": {
"allowedRoles": [ 1, 2, 3 ]
},
"Path.Select": {
"allowedRoles": [ 1, 2, 3 ],
"result-1": {
}
},
"Path.Delete": {
"allowedRoles": [ 1, 2 ]
},
"User.Select": {
"allowedRoles": [ 1, 2, 3 ],
"result": {
"select": [ "id", "pathid", "roleid", "name", "email", "login", "props" ],
"restrict": [ "password" ]
},
"result-1": {
"select": "*",
"group": true
}
},
"User.Create": {
"allowedRoles": [ 1, 2 ],
"result": {
"select": [ "id", "pathid", "roleid", "name", "email", "login", "props" ],
"restrict": [ "password" ]
},
"result-1": {
"select": "*",
"group": true
}
},
"User.Update": {
"allowedRoles": [ 1, 2, 3 ],
"result": {
"select": [ "id", "pathid", "roleid", "name", "email", "login", "props" ],
"restrict": [ "password" ]
}
},
"User.Delete": {
"allowedRoles": [ 1, 2 ],
"result": {
"restrict": [ "password" ]
}
},
"Session.Select": {
"allowedRoles": [ 1, 2, 3 ],
"enforcePathLevel": true,
"result": {
"default": [ "name", "beginDate", "endDate" ],
"restrict": [ "password" ]
},
"result-1": {
"default": [ "name", "beginDate", "endDate" ],
"treeAllowed": true,
"treeDefault": false
}
},
"Session.Create": {
"allowedRoles": [ 1, 2 ],
"enforcePathLevel": true
},
"Session.Update": {
"allowedRoles": [ 1, 2 ],
"enforcePathLevel": true,
"update-restictions": [ "password" ],
"update-restictions-1": [ ],
"result": {
"restrict": [ "password" ]
}
},
"Session.Delete": {
"allowedRoles": [ 1, 2 ],
"result": {
"restrict": [ "password" ]
}
},
"Team.Select": {
"allowedRoles": [ 1, 2, 3 ],
"enforcePathLevel": false,
"enforcePathLevel-1": true,
"result-1": {
"treeAllowed": true,
"treeDefault": false
}
},
"Team.Create": {
"allowedRoles": [ 1, 2, 3 ],
"enforcePathLevel": true,
"enforcePathLevel-1": false,
"allowMultiple": false,
"allowMultiple-1": true,
"result": {
},
"overrides": {
"roleID": 3
}
},
"Team.Reset": {
"allowedRoles": [ 1, 2, 3 ]
},
"Team.Delete": {
"allowedRoles": [ 1, 2, 3 ],
"deleteMultiple": true,
"result": {
"default": "t"
}
},
"Team.TransitionTo": {
"allowedRoles": [ 1, 2, 3 ],
"inboundRules": {
"Round1Init": {
"allowedRoles": [ ]
}
},
"outboundRules": {
"Round1Wait": {
"allowedRoles": [ 1, 2, 3 ]
}
}
},
"Team.TakeControl": {
"allowedRoles": [ 1, 2, 3, 4 ],
"select-1": {
"select": "*",
"restrict": [ "ctrl.userID", "ctrl.loginName" ]
}
},
"Team.ReleaseControl": {
"allowedRoles": [ 1, 2, 3, 4 ],
"select-1": {
"select": "*",
"restrict": [ "ctrl.userID", "ctrl.loginName" ]
}
},
"Team.GetStatus": {
"allowedRoles": [ 1, 2, 3 ],
"result": {
"default": "p,t,pr"
}
},
"Data.Select": {
"allowedRoles": [ 1, 2, 3 ]
},
"Data.Update": {
"allowedRoles": [ 1, 2, 3 ],
"audit": {
"g": false,
"i": true,
"o": true,
"s": true
}
},
"Data.ExecuteQuery": {
"allowedRoles": [ 0, 1, 2, 3 ],
"allowed-0": [ "login4\\areas", "login4\\regions", "login4\\sessions", "login4\\teams" ],
"restrict-3": [ "prohibitedQueryNameHere" ]
},
"Document.Select": {
"defaultTextEncoding": "utf-16"
},
"Document.Create": {
"~allowFileExt": [ ],
"denyFileExt": [ ".exe", ".com", ".cmd", ".bat", ".ps1" ],
"~allowContentType": [ ],
"denyContentType": [ "application/x-msdownload" ],
"maxContentLength": 0,
"defaultTextEncoding": "utf-16"
},
"Document.Update": {
"allowedRoles": [ 1, 2, 3 ]
},
"Document.Delete": {
},
"Document.Download": {
}
}
}
Your json is missing the starting and ending curly brackets:
{
"policies": {
"Framework.DataContext": {
"connectionString": "Server=ServerName;Database=DateBaseName;Integrated Security=sspi;"
}
}
}
Now you can update the file like this:
$pathToJson = "F:\Path\To\JSON\file.json"
$a = Get-Content $pathToJson | ConvertFrom-Json
$a.policies.'Framework.DataContext'.connectionString = "Server=ServerName;Database=DateBaseName;Integrated Security=sspi2;"
$a | ConvertTo-Json | set-content $pathToJson
You could also use some Select-Object to get the property:
$connectionString = $a | select -expand policies | select -expand Framework.DataContext
$connectionString.connectionString = 'Test'
$s = Get-Content "F:\Path\To\JSON\file.json" -Raw|ConvertFrom-Json
$s.policies.'Framework.DataContext'.connectionString="Server=ServerName;Database=DateBaseName;Integrated Security=sspi2;"
$s|ConvertTo-Json |Set-Content "F:\Path\To\JSON\file.json"
I also faced the similar problem. Fixed it by specifying the INDEX of the object I was trying to edit.
$a.policies[0].'Framework.DataContext'.connectionString = "Server=ServerName;Database=DateBaseName;Integrated Security=sspi;"
Hope it helps!