Skip to content

How to get a single item in storage layer with fs or github adapter #1455

Answered by Hebilicious
learntheropes asked this question in Q&A
Discussion options

You must be logged in to vote

Load the json file first. getItem will parse the json file into a JS object, so you can access its property directly.

  const json = await useStorage('db').getItem(`${lang}.json`);
  return json.hallo;

I don't understand, what are you trying to achieve ?
If you want to modify that property with setItem, you have to pass the entire modified file, not just the property :

  const json = await useStorage('db').getItem(`${lang}.json`);
  const newJson = {...json, hallo: "hello there"}
  await useStorage('db').setItem(`${lang}.json`, newJson);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@learntheropes
Comment options

Answer selected by Hebilicious
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants