How to write and save json file in local storage?

Dear All,
Can you share me the code snippet for write and save the json file in local storage.

Thanks in advance.

localStorage.setItem('my-unique-key', JSON.stringify({ x: 5, y: 6 }));

MDN docs for setItem
MDN docs for JSON.stringify

Can I access and use it(json file) in off-line mode?

I want to save json file in local folder and overwrite it on runtime whenever I need. Is it possible?

Yea, local storage is available in offline mode.

Can you share me sample code to write the json file and save it in local.

Thanks in advance

@will shared that above, it’s not a file, it’s an entry to the local storage cache.

If I should be work with android platform in off-line mode. How could I access the json file to overwrite the fields. Also, I need to create json file at runtime.

How are you running PlayCanvas on Android? What system do you use?

Using Ionic framework(web view), I was taken android apk and It has been working successfully.

Yes, Ionic works great with PlayCanvas, it’s a great library. Then you should consult the Ionic API on how to write and read a file, that is responsible with interacting with the OS.

The PlayCanvas instance runs in a webview context and can’t do that.

I am using same scenario with iOS development. Can you suggest me. How to create and modify the text file in local storage? (It should be work both off-line and on-line mode). Is it possible?

Is Playcanvas having File System API?

Thanks in advance.

Ionic has a native plugin for that, check this:

1 Like

Thank you for sharing.

I am using same scenario with iOS development. Can you suggest me. How to create and modify the text file in local storage? (It should be work both off-line and on-line mode). Is it possible?

Is Playcanvas having File System API?

Thanks in advance.

Ionic plugins I think work cross platform, so it will be the same. If that’s not the case that is something to discuss with their support or in their forums.