javascriptnode.jsjsonjsonstream

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-Structure

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.


Solution

  • 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