简体   繁体   中英

Cant use JSON Stream for JSON Objects

I am working on big JSON data and used JSONStream npm module for parsing it. I can parse data from JSON Array Object. But one of scnerios get a simple JSON object(not array).

In this case, I am not able to parse multiple fields. I am able to parse/extract only one field.

My Json Structure, i want to parse/extract status.replicas and status.updatedReplicas

JSON结构

My code,

request({url:'ssss',verify:'False',headers:{'Authorization':'Bearer zzzz','Accept':'application/json','User-Agent':'zzz'}})
  .pipe(JSONStream.parse('status.replicas'))
  .pipe(es.mapSync(function (data) {
    console.log("Log "+data); 
  })) ;

This is giving data =1 how can I parse both replicas and updatedReplicas

If I use JSONStream.parse('*') then output data = Deployment it is taking only kind element form my JSON.

What you should do is access status , and then use data.updatedReplicas & data.replicas

request({url:'ssss',verify:'False',headers:{'Authorization':'Bearer zzzz','Accept':'application/json','User-Agent':'zzz'}})
  .pipe(JSONStream.parse('status'))
  .pipe(es.mapSync(function (data) {
    console.log("Log ", data.replicas, data.updatedReplicas); 
  })) ;

Note: event-stream has been archived

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM