반응형
PowerShell을 사용하여 JSON 파일을 업데이트하는 방법
1개의 json 파일이 있습니다.mytest.json
아래처럼 값을 업데이트하려면PowerShell script
update.json
{
"update": [
{
"Name": "test1",
"Version": "2.1"
},
{
"Name": "test2",
"Version": "2.1"
}
]
}
PowerShell 스크립트를 작성하고 싶다.if Name=="test1" I want to update Version= "3"
매개 변수를 사용하여 어떻게 합니까?
방법은 다음과 같습니다.
$a = Get-Content 'D:\temp\mytest.json' -raw | ConvertFrom-Json
$a.update | % {if($_.name -eq 'test1'){$_.version=3.0}}
$a | ConvertTo-Json -depth 32| set-content 'D:\temp\mytestBis.json'
@FLGMwt와 @mikemaccana에 따라 개선합니다.ConvertTo-Json
와 함께-depth 32
기본 깊이 값은 2이고 2보다 큰 객체의 경우 객체에 관계없이 클래스 정보를 수신합니다.
나도 같은 문제에 직면했다.아래 JSON 파일의 레코드를 변경하려고 합니다.
{
"SQS_QUEUE_URL": "https://que-url.com/server1",
"SQS_EVENTS_QUEUE_URL": "https://events-server.com/server1/development_events",
"REGION": "region1",
"BUCKET": "test-bucket",
"AE_WORK_PATH": "C:\\workpath\\path1",
"ENV": "env"
}
마지막으로 Powershell에서 JSON 파일을 생성하는 가장 쉬운 방법을 찾을 수 있었습니다.
$json = Get-Content "c:\users\bharat.gadade\desktop\test.json" | ConvertFrom-Json
$json.SQS_QUEUE_URL = "https://que-url.com/server2"
$json.SQS_EVENTS_QUEUE_URL = "https://events-server.com/Server2/development_events"
$json.REGION = "region1 "
$json.BUCKET = "test-bucket"
$json.AE_WORK_PATH = "C:\workpath\path1"
$json.ENV = "env"
$json | ConvertTo-Json | Out-File "c:\users\bharat.gadade\desktop\test.json"
언급URL : https://stackoverflow.com/questions/35865272/how-do-i-update-json-file-using-powershell
반응형
'sourcetip' 카테고리의 다른 글
경로 "_id"에서 값 XXX에 대한 Mongoose 오류 ObjectId에 캐스트 실패했습니다. (0) | 2023.02.17 |
---|---|
Webrick은 반응이 매우 느리다.어떻게 하면 빨라요? (0) | 2023.02.17 |
리액트 리덕스: 리덕터에 논리가 포함되어 있는지 여부 (0) | 2023.02.17 |
리액트 스테이트리스 컴포넌트 이벤트핸들러 (0) | 2023.02.17 |
여러 고유 ID를 사용한 Rest API 설계 (0) | 2023.02.17 |