How can I get the email address from the following JSON feed? - json

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;
}
}
}
}
}

Related

JQ: Add object to nested json with the same key names

I having trouble of getting my json append with a new object into the config -> list -> key(vehicles) -> Rows. But then only for vehicles.
Im trying it with JQ: cat file.json | jq '.config.list[].rows[] += {"data":[{"key":"fort","value":"K"},{"key":"seat","value":"leon"}],"default":false}' But with this it is replacing and not appending because of the same names ?
Object that needs to
{
"data": [
{
"key": "bike",
"value": "yyy"
},
{
"key": "car",
"value": "xxx"
}
],
"default": false
}
Source Json:
{
"id": "1234",
"name": "CatList",
"config": {
"list": [
{
"key": "vehicles",
"rows": [
{
"data": [
{
"key": "bike",
"value": "yyy"
},
{
"key": "car",
"value": "xxx"
}
],
"default": false
}
]
},
{
"key": "boots",
"rows": []
}
],
"data": [
{
"key": "GROUPS",
"value": "false"
}
]
}
}
Wanted result:
{
"id": "1234",
"name": "CatList",
"config": {
"list": [
{
"key": "vehicles",
"rows": [
{
"data": [
{
"key": "bike",
"value": "yyy"
},
{
"key": "car",
"value": "xxx"
}
],
"default": false
},
{
"data": [ <-----
{ <-----
"key": "bike", <-----
"value": "yyy" <-----
}, <-----
{ <-----
"key": "car", <-----
"value": "xxx" <-----
} <-----
], <-----
"default": false <-----
}
]
},
{
"key": "boots",
"rows": []
}
],
"data": [
{
"key": "GROUPS",
"value": "false"
}
]
}
}
You were close
jq '.config.list[.config.list|map(.key=="vehicles")|index(true)].rows += [{"data":[{"key":"fot","value":"K"},{"key":"seat","value":"leon"}],"default":false}]'
see https://stackoverflow.com/a/42248841/2235381

Sort complex JSON object by specific property

How can I sort the given JSON object with property count. I want to sort the entire sub-object. The higher the count value should come on the top an so on.
{
"Resource": [
{
"details": [
{
"value": "3.70"
},
{
"value": "3.09"
}
],
"work": {
"count": 1
}
},
{
"details": [
{
"value": "4"
},
{
"value": "5"
}
],
"work": {
"count": 2
},
{
"details": [
{
"value": "5"
},
{
"value": "5"
}
],
"work": "null"
}
]
}
You can try this example to sort your data:
data = {
"data": {
"Resource": [
{
"details": [{"value": "3.70"}, {"value": "3.09"}],
"work": {"count": 1},
},
{"details": [{"value": "4"}, {"value": "5"}], "work": {"count": 2}},
]
}
}
# sort by 'work'/'count'
data["data"]["Resource"] = sorted(
data["data"]["Resource"], key=lambda r: r["work"]["count"]
)
# sort by 'details'/'value'
for r in data["data"]["Resource"]:
r["details"] = sorted(r["details"], key=lambda k: float(k["value"]))
# pretty print:
import json
print(json.dumps(data, indent=4))
Prints:
{
"data": {
"Resource": [
{
"details": [
{
"value": "3.09"
},
{
"value": "3.70"
}
],
"work": {
"count": 1
}
},
{
"details": [
{
"value": "4"
},
{
"value": "5"
}
],
"work": {
"count": 2
}
}
]
}
}

Is it possible to print the value of Key from the (key-value)pair of json object in laravel

How to print the 'key' value from the json object in laravel.
The json array:
"pricing": {
"in": {
"categories": [
"ccTLD",
"Geography"
],
"addons": {
"dns": true,
"email": true,
"idprotect": true
},
"group": "",
"register": {
"1": "704.39"
},
"transfer": {
"1": "704.39"
},
"renew": {
"1": "704.39"
}
},
How to display "in" from the above data?
Put JSON in a variable. Ex. $jsonVariable.
json_decode($jsonVariable)->pricing->in
First of all i think there is some mistake in your json here is my funtion with two ways of achiving the same thing
public function demo()
{
$json_array = '
{
"pricing": {
"in": {
"categories": [
"ccTLD",
"Geography"
],
"addons": {
"dns": true,
"email": true,
"idprotect": true
},
"group": "",
"register": {
"1": "704.39"
},
"transfer": {
"1": "704.39"
},
"renew": {
"1": "704.39"
}
}
}
}
';
echo "<pre>";
print_r(json_decode($json_array)->pricing->in);
$asso_array = json_decode($json_array, true);
print_r($asso_array["pricing"]["in"]);
exit;
}

WebServerInstance Encountered unsupported property VpcId

I keep getting this issue in the Webserversinstance.
*Paramaters*
VPCSelection": {
"Description": "VPC",
"Type": "String",
"Default": "vpc-xxxxxxx"
*Webserver Security group*
"Resources": {
"WebServerSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"VpcId": {
"Ref": "VPCSelection"
},
*WebServer Instance*
{
"Resources": {
"WebServerSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"VpcId": {
"Ref": "VPCSelection"
},
When i run this template, i get this issue:
12:45:52 UTC+0000 ROLLBACK_IN_PROGRESS AWS::CloudFormation::Stack Test13 The following resource(s) failed to create: [WebServerInstance]. . Rollback requested by user.
12:45:51 UTC+0000 CREATE_FAILED AWS::EC2::Instance WebServerInstance Encountered unsupported property VpcId
When i remove this VPCid from the webserver instance i get a different error saying: AWS::EC2::Instance WebServerInstance No default VPC for this user
I put this into Bisque and got the below. Does this help?
{
"Resources": {
"WebServerSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Metadata": {
"YadaYada::Bisque::DotnetType": {
"Type": "Bisque.EC2.Networking.SecurityGroup, Bisque.Aws, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
}
},
"Properties": {
"GroupDescription": {
"Ref": "WebServerSecurityGroupGroupDescription"
},
"VpcId": {
"Ref": "VPCSelection"
},
"Tags": [
{
"Key": "Name",
"Value": "WebServerSecurityGroup"
}
]
}
},
"WebServerInstance": {
"Type": "AWS::EC2::Instance",
"Metadata": {
"YadaYada::Bisque::DotnetType": {
"Type": "Bisque.EC2.Instances.Instance, Bisque.Aws, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
},
"AWS::CloudFormation::Init": {
"configSets": {
"Bootstrap": [
"Bootstrap"
]
},
"Bootstrap": {
"services": {
"windows": {
"cfn-hup": {
"ensureRunning": true,
"enabled": true,
"files": [
"c:\\cfn\\hooks.d\\cfn-auto-reloader.conf",
"c:\\cfn\\cfn-hup.conf"
]
}
}
},
"files": {
"c:\\cfn\\hooks.d\\cfn-auto-reloader.conf": {
"content": {
"Fn::Join": [
"\n",
[
"[cfn-auto-reloader-hook]",
"triggers=post.update",
"path=Resources.WebServerInstance.Metadata.AWS::CloudFormation::Init",
{
"Fn::Join": [
"",
[
"action=",
{
"Fn::Join": [
"",
[
"cfn-init.exe -v -c \"",
"Bootstrap",
"\" -s ",
{
"Ref": "AWS::StackId"
},
" -r WebServerInstance --region ",
{
"Ref": "AWS::Region"
}
]
]
}
]
]
}
]
]
}
},
"c:\\cfn\\cfn-hup.conf": {
"content": {
"Fn::Join": [
"\n",
[
"[main]",
{
"Fn::Join": [
"",
[
"stack=",
{
"Ref": "AWS::StackName"
}
]
]
},
{
"Fn::Join": [
"",
[
"region=",
{
"Ref": "AWS::Region"
}
]
]
},
"interval=1",
"verbose=true"
]
]
}
}
}
}
}
},
"Properties": {
"SecurityGroupIds": [
{
"Ref": "WebServerSecurityGroup"
}
],
"Tags": [
{
"Key": "Name",
"Value": "WebServerInstance"
}
],
"ImageId": {
"Ref": "WebServerInstanceImageId"
},
"InstanceType": {
"Ref": "WebServerInstanceInstanceType"
},
"KeyName": {
"Ref": "WebServerInstanceKeyName"
},
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"<script>",
{
"Fn::Join": [
"",
[
"cfn-init.exe -v -c \"",
"Bootstrap",
"\" -s ",
{
"Ref": "AWS::StackId"
},
" -r WebServerInstance --region ",
{
"Ref": "AWS::Region"
}
]
]
},
"</script>"
]
]
}
}
}
}
},
"Parameters": {
"VPCSelection": {
"Type": "AWS::EC2::VPC::Id"
},
"WebServerSecurityGroupGroupDescription": {
"Type": "String"
},
"WebServerInstanceImageId": {
"Type": "AWS::EC2::Image::Id"
},
"WebServerInstanceInstanceType": {
"Type": "String",
"Default": "t2.micro",
"AllowedValues": [
"",
"t2.nano",
"t2.micro",
"t2.small",
"t2.medium",
"t2.large",
"t2.xlarge",
"t2.2xlarge",
"m4.large",
"m4.xlarge",
"m4.2xlarge",
"m4.4xlarge",
"m4.10xlarge",
"m3.medium",
"m3.large",
"m3.xlarge",
"m3.2xlarge",
"m1.small",
"m1.medium",
"m1.large",
"m1.xlarge",
"c4.large",
"c4.xlarge",
"c4.2xlarge",
"c4.4xlarge",
"c4.8xlarge",
"c3.large",
"c3.xlarge",
"c3.2xlarge",
"c3.4xlarge",
"c3.8xlarge",
"c1.medium",
"c1.xlarge",
"cc2.8xlarge",
"cc1.4xlarge",
"g2.2xlarge",
"g2.8xlarge",
"cg1.4xlarge",
"r3.large",
"r3.xlarge",
"r3.2xlarge",
"r3.4xlarge",
"r3.8xlarge",
"x1.32xlarge",
"m2.xlarge",
"m2.2xlarge",
"m2.4xlarge",
"cr1.8xlarge",
"d2.xlarge",
"d2.2xlarge",
"d2.4xlarge",
"d2.8xlarge",
"i2.xlarge",
"i2.2xlarge",
"i2.4xlarge",
"i2.8xlarge",
"hi1.4xlarge",
"hs1.8xlarge",
"t1.micro"
]
},
"WebServerInstanceKeyName": {
"Type": "AWS::EC2::KeyPair::KeyName",
"Default": "default"
}
},
"Metadata": {
"AWS::CloudFormation::Interface": {
"Key": "AWS::CloudFormation::Interface",
"ParameterGroups": [
{
"Label": {
"default": "WebServerSecurityGroup Properties"
},
"Parameters": [
"WebServerSecurityGroupGroupDescription"
]
},
{
"Label": {
"default": "WebServerInstance Properties"
},
"Parameters": [
"WebServerInstanceImageId",
"WebServerInstanceInstanceType",
"WebServerInstanceKeyName"
]
}
],
"ParameterLabels": {
"WebServerSecurityGroupGroupDescription": {
"default": "Description"
},
"WebServerInstanceImageId": {
"default": "Image Id (AMI)"
},
"WebServerInstanceInstanceType": {
"default": "Instance Size"
},
"WebServerInstanceKeyName": {
"default": "Key Name"
}
}
}
}
}

Update JSON file using PowerShell

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!