PSport
PSport

Reputation: 139

Download json file content jQuery node js

I'm using an app based on node js and jquery. I'm manipulating JSON files and I'd like to allow users to download a JSON file config (only one part of a JSON object). Let me show you an exemple :

{
    "CARS": {
        "1": {
            "NAME": "CAR1",
            "BRAND": {},
            "SIZE": 12,
            "THEME": {
                "COLOR": "#555555",
                "WHEELS": "4"
            },
            "GARAGE_ID": "1",
            "ID": 1
        }
    }
}

Eg : I'd like to allow user to download the theme of this car into a JSON file. Then he will be able to upload it later if he needs this theme again.

How can I generate a JSON file using jQuery / Node jS ?

Thanks

Upvotes: 0

Views: 110

Answers (1)

Mukesh Sharma
Mukesh Sharma

Reputation: 9032

If I understand you problem correctly, then you can do it by the following.

var express =require('express');
var app = express();

app.get('/', function(req,res){
   var data = {
      "CARS": {
          "1": {
              "NAME": "CAR1",
              "BRAND": {},
              "SIZE": 12,
              "THEME": {
                "COLOR": "#555555",
                "WHEELS": "4"
              },
              "GARAGE_ID": "1",
              "ID": 1
          }
      }
   };
   return res.json(data["CARS"]["1"]["THEME"]);
});

app.listen(3000,'localhost');

Upvotes: 1

Related Questions