首先安装 js-yaml
npm install js-yaml
let content='kind: StoqweqrageClasqwes
apiVersion: qwe.k8sqwe.io/v1
metadata:
name: locaqwel
resourceVersion: 'qwe'
annotations:
kubectl.kubernetes.io/last-applied-configuration: >
{"apiVeqwersion":"storqweqweage.k8s.io/v1","kind":"StorageClass","metadata":{"annqweqotations":{"storaqwewegecqwelass.beta.kubernetes.io/is-default-class":"true","storageclass.kubesphere.io/supporqweqewted_access_modes":"[\"ReadWriteOnce\"]"},"name":"local"},"provisioner":"kubernetes.io/no-provisioner","volumeBindingMode":"WaitForFirstConsumer"}
storaqwegeclass.beta.kubernetes.io/is-default-class: 'true'
storqweageclass.kubesphere.io/suppoqwerted_access_modes: '["qweqe"]'
provisioner: kubernetes.io/no-provqweisioner
reclaimPolicy: Deqwelete
volumeBindiqwengMoqwede: WaitForFirqweqwestConsumer'
let yaml = require("js-yaml");
let result = yaml.load(content);
console.log(JSON.stringify(result, null, 2));