Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

Can some body please explain , I have a large data in my json file and i have to select at some point like data === smp('Report').

smp( "Reports" ) {
            smp( "firewall_real_time" ) {
                smp( "Appearance Settings" ) {
                    int( "Alignlogo" ) = 1812531465
                    int( "Alignlogo2" ) = 980706917
                    str( "Alignment" ) = ""
                    int( "Diagram Background Color" ) = 16777215
                    smp( "Fonts" ) {
                        smp( "Copyright" ) {
                            int( "Size" ) = 10
                            int( "Width" ) = 300
                            int( "XAxis" ) = 500
                            int( "YAxis" ) = 50
                        }
                    }
// I have to add extra data here so please help me how to add in between { { } }.
                 }
              }

Thank you in advance!

share|improve this question

1 Answer 1

This is pretty easy. I don't know your json file structure, but if you simply:

var data = require('./report.json');

Then "data" is just a regular JS object with all the same structure as in the file. So if it looks like

{ "reports" : [ { "firewall_status" : "on"}]}

Or something like that, then data could do :

console.log(data.reports[0].firewall_status); 

and it would print "on".

likewise, you could do something like

data.reports.push({firewall_status : "off"});

or whatever else you'd do with a plain old JS object.

When you're done, you'll probably want to write the data back to disk, so you would do so by stringifying the object and writing it out w/ the fs module:

fs.writeFile('./report.json', JSON.stringify(data, null, 4), function(err) {
    if(err) {
      console.log(err);
    } else {
      console.log('JSON saved');
    }
}); 
share|improve this answer
    
The above code which i added ,I just copied few lines from 12790 KB.so if whole file data equal to data then i think i have to use if(data === (smp('Reports)') { } like that . but i am confusing there are multiple '{' and '}'. if i want to add data between {,{,{ data.substring() },},}. – Kirankamana Sep 23 '14 at 13:23
    
? I don't understand your comment. I understand your overall JSON file is more complex than you wrote out, but what I answered will still let you access and modify the information in it, you just might have to nest more deeply. That said, if you're looking at a data structure that's 12 MB big, you might consider a database such as MongoDB rather than a single JSON file in any case. – Paul Sep 23 '14 at 13:27
    
Thanks, I am sorry that is not a json file. It's in Gcf format. – Kirankamana Sep 23 '14 at 13:42
    
smp( 9 ) { int( "Active" ) = 1 str( "Name" ) = "windows_monitoring" vec( "Params" ) { str( 0 ) = ".\\res\\Reports" str( 1 ) = "windows_monitoring" } int( "Type" ) = 9 } } str( "Last Modification Date" ) = "2014/04/17 16:40:13" str( "ListPath" ) = "REAL-TIME" int( "StopOnFailure" ) = 1 } // As you see after the above code ''smp( "Reports" ) {'' starts. – Kirankamana Sep 23 '14 at 13:46
    
? your question explicitly states that you're working with a JSON file. – Paul Sep 23 '14 at 23:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.