如何转换这样的JSON文档:
[8,1,2,3,4,5,6,7]
变成这样:
function renerateRandomNumbers(maxNumber, randomNumbersCount) {
var candidates = [...Array(maxNumber).keys()];
return Array(randomNumbersCount).fill()
.map(() => {
const randomIndex = Math.floor(Math.random() * candidates.length)
const n = candidates[randomIndex]
candidates[randomIndex] = candidates[candidates.length - 1]
candidates.length = candidates.length - 1
return n
})
.sort((a, b) => a - b) // sort if needed
}
console.log (renerateRandomNumbers(10, 5))
使用命令行工具{ "foo": 123, "bar": "abc" }
?
答案 0 :(得分:2)
您只需要在输入周围包裹一个对象即可。
jq '{payload: .}' some.json