dikt icon indicating copy to clipboard operation
dikt copied to clipboard

Cannot open one json dictionary

Open yumeo-ch opened this issue 1 year ago • 7 comments

Hello, Thank you for the job first of all. There is a dictionary I want to open : https://github.com/VahidN/EnglishToPersianDictionaries/blob/master/Dictionaries/subtitles/B.json But it doesn't work with dikt, how can I open this JSON file? Pyglossary doesn't read json files and I couldn't find another app capable of doing so.

yumeo-ch avatar May 28 '23 07:05 yumeo-ch

That's a different json format. Can you open a discussion here? https://github.com/ilius/pyglossary/discussions

ilius avatar May 28 '23 08:05 ilius

Hi, thanks for the interest. The problem is due to DIKT expecting a different structure of JSON. In your case you have this:

{
  "Group": "B",
  "Entries": 21736,
  "Words": [
    {
      "EnglishWord": "b  cardinal richelieu",
      "Meanings": [
        "ب کاردینال ریچلیو"
      ]
    },
    {
      "EnglishWord": "b  franklin roosevelt",
      "Meanings": [
        "ب فرانکلین روزولت"
      ]
    }
  ]

while the app expects a simpler structure with keys being words and values being translations, e.g.:

 {
  "b  cardinal richelieu": "ب کاردینال ریچلیو",
  "b  Franklin roosevelt": "ب فرانکلین روزولت"
}

Here's an example JS to transform the structure you shared to JSON that is supported by DIKT:

function transformJson(input) {
  const output = {};

  input.Words.forEach(word => {
    const englishWord = word.EnglishWord;
    const meanings = word.Meanings.join('\n');
    output[englishWord] = meanings;
  });

  return output;
}

const inputJson = {
  "Group": "B",
  "Entries": 21736,
  "Words": [
    {
      "EnglishWord": "b  cardinal richelieu",
      "Meanings": [
        "ب کاردینال ریچلیو"
      ]
    },
    {
      "EnglishWord": "b  franklin roosevelt",
      "Meanings": [
        "ب فرانکلین روزولت"
      ]
    }
  ]
};

const transformedJson = transformJson(inputJson);
console.log(transformedJson);

maxim-saplin avatar May 28 '23 08:05 maxim-saplin

Hey, thank you for great explanation, but doing so doesn't resolve the issue, I still have error when importing the JSON file with your structure (I even have error when I copy paste your example code in a bank file and save it as test.json).

yumeo-ch avatar May 28 '23 19:05 yumeo-ch

Please share the file with the supported structure for me to look at

maxim-saplin avatar May 28 '23 19:05 maxim-saplin

Please share the file with the supported structure for me to look at

https://1fichier.com/?ckrc0f8zbn8r6ywhfn6b

Sure, here you are

yumeo-ch avatar May 28 '23 19:05 yumeo-ch

Apparently the file you provided is not JSON (but rather some piece of JS) and can not work in principle, no matter the structure which is supported by the app.

image

maxim-saplin avatar May 29 '23 06:05 maxim-saplin

I see, do you know any solution or any way to "convrrt" them ? I guess it shouldn't be that hard. I would open a discussion on pyglossary as well.

yumeo-ch avatar May 29 '23 07:05 yumeo-ch