Open husainaloos opened 6 years ago
replacing current array values is not problem.
my_array[1]/@value
however, if item does not exist, you have to explicitly add it using:
my_array[]`1/@value
@sergeyzwezdin , hi! Is there any way to do this:
[
{
"field1": "value1",
"field2": "value2"
} ....
]
{
"field1": "value3",
"field2": "value4"
}
@Sigman32 Thanks for sharing! I have some questions regarding this,
I have a simple array like this in my configs
"my_array": [ "value1", "value2" ], In the transform task I added this "my_array[0]" : "value1" "my_array[1]" : "value2"
The end result is a new entry at the end of the config exactly like the following, seems like the task isn't evaluating it as an array but rather as strings "my_array[0]" and "my_array[1]" "my_array[0]" : "value1" "my_array[1]" : "value2"
If I do this however, it adds new additional items in the array without issues "my_array[]" : "value1" "my_array[]" : "value2"
Do you have any ideas what I might be doing wrong? Thank you. :)
This doesn't seem to work. I'm trying to replace the following at the bottom of this JSON:
{
"Serilog": {
"Using": [
"Serilog.Sinks.ApplicationInsights"
],
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp} [{Level}] {Message} {Exception} {Properties} {NewLine}",
"theme": "Serilog.Sinks.SystemConsole.Themes.SystemConsoleTheme::Literate, Serilog.Sinks.Console"
}
},
{
"Name": "File",
"Args": {
"path": ".\\Logs\\ApiService.log",
"fileSizeLimitBytes": 10000000
}
},
{
"Name": "ApplicationInsights",
"Args": {
"logName": "ApiService",
"instrumentationKey": "<THIS IS WHAT I WANT TO REPLACE>",
...
I use this path:
Serilog/WriteTo[2]/Args/instrumentationKey
But it just creates a new "WriteTo[2]" section below Serilog - it doesn't replace the existing second item (the one for Azure App Services).
"my_array": [ "value1", "value2" ],
So how can we change these settings?
Workaround.
.NET Configuration supports different syntax. see: Configuration in ASP.NET Core
For example, you can define multiple WriteTo sections with index:
"Serilog": {
"WriteTo:0": {
"Name": "Console",
"Args": {
}
},
"WriteTo:1":{
"Name": "File",
"Args": {
"path": "./logs/log-.log",
}
},
}
and use path: Serilog/WriteTo:1/Args/path
replacing current array values is not problem.
my_array[1]/@value
however, if item does not exist, you have to explicitly add it using:
my_array[]`1/@value
I need to add new array element in appsetting, but this does not work
Does this tasks support replacing an item in a JSON array in configuration?
Suppose I have this json:
and I want to transform it to
what would be the path to do that?