안녕하세요,
HTTP API 호출로 보낼 JSON을 만들고 있는데 문법의 한 부분에서 막혔어요.
코드는 이래요:
$payload = [ordered]@{
resourceType = 'Parameters';
parameter = @{
name = 'Valueset'
}
}
write-host ($payload | ConvertTo-JSON)
해시 테이블을 정의한 뒤 JSON으로 바꾸는 접근이 맞나요? Powershell 초보라서 혼자 공부하다 나쁜 습관이 들까 봐요.
구체적으로는 다음 두 상황에서 parameter가 배열이어야 해요:
name 속성이 실제로 여러 개일 때요.
그리고 여기처럼 하나뿐이어도 API에서 그 값을 json 배열로 받도록 요구할 때요.
몇 가지 방법을 시도했지만 잘 안 돼서, 올바르게 하는 방법을 알려 주시면 좋겠어요.
감사합니다
영어에서 번역·원문 보기Hi,
I'm building JSON to send in an HTTP API call, and one aspect of the syntax has me stuck.
Here's the code:
$payload = [ordered]@{
resourceType = 'Parameters';
parameter = @{
name = 'Valueset'
}
}
write-host ($payload | ConvertTo-JSON)
Am I right that defining a hash table and then turning that into JSON is the correct approach? As a Powershell newcomer, I want to avoid picking up bad habits while teaching myself.
What I specifically need is an array for parameter under two circumstances:
If there's actually more than one name attribute.
If there's just one, like here, but the API expects that value to be represented as a json array.
I've attempted a few approaches without success, so I'd welcome any guidence on getting this right.
Cheers