Exploring data stored in JSON format

I'm currently attempting to access my i18n-strings from a JSON file by following the instructions in this particular guide.

In my possession is a file named en-US.json:

{
  "world": "the world!"
}

To set up my Vue application, I am employing:

import { createI18n } from 'vue-i18n'
import enUS from '../src/i18n/en-US.json'

// Ensuring 'en-US' is defined as the leading structure for the resource
type MessageSchema = typeof enUS

const i18n = createI18n<[MessageSchema], 'en-US'>({
  locale: 'en-US',
  messages: {
    'en-US': enUS
  }
})

This method functions properly. However, upon introducing a non-ASCII character (e.g.

"world": "the w@rld!"
), an error message emerges:

[plugin:vite-plugin-vue-i18n] Cannot read properties of undefined (reading 'message')
/home/bernhard/wd/quasar2-project/src/i18n/en-US.json

Coincidentally, this issue does not arise when I directly include the same content in my .ts file:

const enUS = {
   "world": "the w@rld!"
}

This suggests a potential problem with how the JSON data is being processed.

Answer №1

This answer delves into a dual-layered solution.

  1. Highlighted by @jonrsharpe, there exists a specific set of special characters: { } @ $ |, designed for variable insertion. For instance, replacing @ with {'@'}.
  2. An issue arises in the handling of external JSON files by vite, as detailed in this Github bug report. By default, quasar utilizes
    "@intlify/vite-plugin-vue-i18n": "^3.3.1"
    , and rectifying this to
    "@intlify/vite-plugin-vue-i18n": "^7.0.0"
    resolves the problem.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to enhance the appearance of parsed JSON data in your ReactJS application

I have developed a unique XML to JSON converter application that allows users to upload their custom .xml files and convert the content into a JSON object using the xml2json-ltx library. While I have successfully implemented the conversion process, the res ...

Develop a specialized data structure for rows in ag grid that can adapt to changes

I have been working on creating an independent component using ag-grid. The column definitions are passed to this component from my application as input properties, defined like this: interface ColumnDef { field: string; headerName: string; } @Input() ...

Outputting Javascript Strings via PHP

Currently, I am utilizing a web service that generates tables through JavaScript functions. However, I am in need of the table to be generated in plain HTML format instead. One potential solution to achieve this is by transferring the JavaScript string t ...

Why will the experimental activation of React concurrent features in Nextjs 12 disable API routes?

I just upgraded to Next.js version 12 and set up some API routes (e.g. "/api/products"). These routes were functioning properly, but when I enabled concurrentFeatures: true in my next.config.ts, the API routes stopped working. The console display ...

Using the Angular JSON pipe with angular-datatables

I am currently utilizing angular-datatables to exhibit NoSQL de-normalized data in a grid format for visualization purposes. Within my dataset, I have several intricate nested JSON objects and I intend to showcase a specific cell with formatted JSON using ...

Looking for a way to trigger a function on JSTree's refresh event

I have searched through many posts here but cannot find what I am looking for. The version of JSTree that I am using is 3.3.3. My goal is to select a node after a create_node event triggers an AJAX request. Subsequently, JSTree fires the rename_node eve ...

Leveraging JSON syntax with square brackets and without square brackets

When using JSON with square brackets [like [{"ID":"1","name":"Amid","surname":"Nakano"}]], I encounter an error. However, when JSON is used without brackets [{"ID":"1","name":"Amid","surname":"Nakano"}], no error is generated. Here is the code snippet: ...

Accessing a variable within a function in Angular

Recently I started working with Angular and encountered an issue while trying to access a variable inside a function. Below is the code snippet that's causing me trouble: mergeImages() { var imgurl; var canvas: HTMLCanvasElement = this.canv ...

What is the best way to dynamically add data to a JSON file?

image of JSON file Just a heads up: I'm looking to add data directly without the need to write it to a .json file, perhaps by using Angularfire2 database. user = { name: 'Arthur', age: 21 }; const options = {Headers, responseType: &apo ...

Encountering a problem when trying to utilize JSON_TABLE in Oracle database

I am experiencing an issue with the following query: tbl_clob contain data [{"ID":2,"FINACIAL_YEAR":"2020"}]. WITH JSON AS ( SELECT DATA FROM tbl_clob WHERE ldap_id = 'S' AND ROLE_ID = 3 AND ...

Using a comma as a decimal separator for input is not permitted when working with angular/typescript/html

I am facing an issue with my Angular frontend where I have numerous html input fields that trigger calculations upon typing. <input type="text" [(ngModel)]="myModel.myAttribute" (input)="calculate()"> The problem arise ...

Tips for establishing optimal parameters for an object's dynamic property

I am working with an array of objects: export const inputsArray: InputAttributes[] = [ { label: 'Name', type: 'text', name: 'name', required: true }, { label: 'User name ...

Enhance TypeScript functionality with operator overloading

I am currently involved in a project that heavily relies on vector and matrix mathematics, and I am keen on incorporating operator overloading into my code. Although there are Babel plugins available (such as https://github.com/rob-blackbourn/jetblack-ope ...

Unable to utilize Stats.js with @angular/cli version 1.4.4

Attempting to utilize @types/stats with @angular/cli following the guidance at https://github.com/angular/angular-cli/wiki/stories-third-party-lib. However, encountering a tslint error when trying to import * as STATS from 'stats.js'. [ts] Modul ...

Obtaining a data point by referencing a key within a json collection

I am working on an AngularJS function that includes a JSON array like this: $scope.userDetails = [{ name: 'Anil Singh', age: 30 }, { name: 'Reena Singh', age: 25 }]; My goal is to extract all the values of the age key. Here is the co ...

I encountered an error when attempting to retrieve a JSON from a URL using a previously provided solution. What might be causing this issue?

Currently, I am facing an issue while trying to retrieve a JSON file for my memory card game. Even after following the solution provided in this question: How to get json file from HttpClient?, I encounter an error message that is quite confusing for me: h ...

Exploring JSON data and making precise adjustments in JavaScript

I am attempting to create my own database using JavaScript and JSON, but I have encountered some issues along the way. My main struggle is figuring out how to extract specific content from a JSON file. After doing some research, I came across this code sn ...

Determine the field's type without using generic type arguments

In my code, there is a type called Component with a generic parameter named Props, which must adhere to the Record<string, any> structure. I am looking to create a type that can accept a component in one property and also include a function that retu ...

Is that possible to prevent the use of the & symbol in Angular 4 HTTP requests?

Using an HTTP request to save data in my database. The code snippet I used is: const form = '&inputdata=' + myinput + '&rf_date=' + rf_date; return this.http.post(this.rootUrl, form, {headers : this.reqHeader}); In thi ...

The JSON property is not defined

After making an AJAX call to retrieve data, I receive a JSON Object instead of a string. When I log the object, all its properties appear correctly. However, when attempting to log one specific property, it shows up as undefined. Here is a snapshot of my ...