0

I have a locally stored json file as c:\path\jsontext.json. I have a jsp page and .js file, In my .js file I have a javascript object, the data of this javascript object is in json format and i would like to append it to the jsontext.json file

But can figure out a way to do this.

Here is my jsontext.json

[
    {
        "Identifier": "1",
        "Label": "pratik",
        "Categories": "Standard",
        "UpdatedBy": "lno",
        "UpdatedAt": "01-02-2013"

    },
    {
        "Identifier": "2",
        "Label": "2013",
        "Categories": "Standard",
        "UpdatedBy": "lno",
        "UpdatedAt": "01-02-2013"
    }
]

supposing in my .js file i have a javascript object

var JSObject=("[{" +'"example1"'+"},"+ "{" + '"example2"' + "}]");

I want to append this data in my jsontext.json file,

how should I go about it.

I looked at some resources and found that I would require a server side programming language to get this done.

If I try doing this in a java code, then the code is easy to write. The only problem then is the java method will be execute first and then the .js file.

If there is a way - a clickevent on the .js file which can call the java method then it would also work for me.

I have this java code.

import java.io.FileWriter;
import java.io.IOException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

public class JsonSimpleExample {
     public static void main(String[] args) {

    JSONObject JSONObject = new JSONObject();


    try {

        FileWriter file = new FileWriter("c:\\jsontext.json");
        file.write(JSONObject.toJSONString());
        file.flush();
        file.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.print(JSONObject);

     }

}

Where should I include this java code in order to write the item into jsontext.json file.? and. IS there are method in Jquery for this??

2
  • "[{" +'"example1"'+"},"+ "{" + '"example2"' + "}]" wont give you json. Commented Jun 14, 2013 at 4:20
  • thats written just to explain my question. I know thats not the actual json. Commented Jun 14, 2013 at 4:26

1 Answer 1

0

If you need to get access to local file system from browser you might want to check File API

You cannot simply access clients computer from jQuery/JavaScript. User will need to permission that as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.