Converting JSONSchema into TypeScript: Creating a structure with key-value pairs of strings

I am working with json-schema-to-typescript and looking to define an array of strings.

Currently, my code looks like this:

      "type": "object",
      "description": "...",
      "additionalProperties": true,
      "items": {
        "type": "string"
      }

However, when converted to TS, it outputs [k: string]: unknown;

Is there a way for it to generate [k: string]: string; instead?

Appreciate your help in advance

Answer №1

items is typically used with arrays, however in this case it seems you have defined it as

"type": "object"
. Have you considered adjusting the type to
"type": "array"
and removing the additionalProperties?

Answer №2

The solution was to eliminate the items attribute and switch it to

"additionalProperties": { "type": "string" }

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

Obtaining images from the internet using JSON in Android

Attempting to gather news information from the web has been relatively easy so far, as I am able to retrieve the header and subject of the news. However, I have encountered a challenge regarding how to extract images from JSON data. Below is the snippet o ...

Can variables be declared for file paths within the HTML code in a TypeScript file?

We utilize the Vaadin designer to create the frontend of our project. Within the .ts files, we have images where we aim to establish variables for the file paths. Currently, the setup looks like this: <img src="../../themes/light/img/example.jpg&q ...

Converting Python Class Hierarchy Objects into a Pre-Existing JSON Structure

The topic of interest encapsulates my intentions. To provide a clearer picture, let's consider a schema I'm working with (which is defined in terms of python-jsonschema: ): schema = { "type" : "object", "propert ...

Searching for multiple keywords across multiple fields using Elastic search

I've been working on creating a query in Elastic search to search within the text of multiple fields, such as Title and Description. My goal is to search for specific keywords like "obama", "world", and "news" across these fields. I found some informa ...

A code snippet in Python for generating JSON data from user input

I created a Python3 program that writes to a JSON file based on user input. The program is up and running, but I am encountering issues with slashes being included in the output. My desired output, written to a file named sample.json, should look like thi ...

Control the number of documents fetched in the $lookup operation with the specified limit

I have encountered an issue with this query resulting in the following output: { "_id" : ObjectId("5bd22f28f77cfb1f6ce503ca"), "search" : "flarize", "name" : "flarize", "color" : 0, "profil" : "", "banner" : "", "desc" : "", ...

The argument type 'MouseEvent<HTMLButtonElement, MouseEvent>' cannot be assigned to the parameter type 'HTMLElementEvent<HTMLButton>'

Here is the code snippet that I am currently working on and encountering an error in the console: type HTMLElementEvent<T extends HTMLElement> = Event & { target: T; } toggleHandler = (e: HTMLElementEvent<HTMLButtonElement>) => ...

To generate a FHIR REST query, utilize the Firely .NET SDK available at https://github.com/FirelyTeam/fire

I am attempting to craft a FHIR REST request to the NHS eReferral system in order to retrieve a worklist. The JSON structure in the example is currently as follows: { "resourceType": "Parameters", "meta": { ...

Transform a collection of hierarchical strings into JSON using C#

I have a series of strings that represent hierarchical information and are separated by hyphens (3 hyphens indicate separation). My goal is to convert this list into a JSON format so that I can link it to a tree control component. I am in search of a C# s ...

The file or directory npx-cli.js cannot be found in the specified location: ../npm/bin/

Problem Description After creating a new React project using the command below, npx create-react-app my-app --template typescript and utilizing node version v18.15.0, I attempted to set up Prettier for the project following the instructions in the Pretti ...

Encounter a Typescript error when dealing with "app.ws" while using express-ws

I have a small project in mind where I want to create a BabyCam that can be accessed from any web browser using a Raspberry Pi Zero. My plan is to set up a web socket using express-is to stream video to multiple clients. I'm utilizing the raspivid-str ...

Electron and React: Alert - Exceeded MaxListenersWarning: Potential memory leak detected in EventEmitter. [EventEmitter] has 21 updateDeviceList listeners added to it

I've been tirelessly searching to understand the root cause of this issue, and I believe I'm getting closer to unraveling the mystery. My method involves using USB detection to track the connection of USB devices: usbDetect.on('add', () ...

Attempting to deserialize serialized data from Django using JSON.parse

I need assistance with some client-side tasks using Javascript. In my view, I serialize a Queryset from my models into JSON and pass it to the template. data = serializers.serialize("json", Profile.objects.filter(user_id=self.request.user)) This results ...

Require assistance in understanding JSON data in the form of a variable

Apologies for any language barriers, but I have encountered a problem that I need help with. I am trying to create a highchart from an AJAX call. The following code works perfectly: chartOptions = { chart: { renderTo: 'grafica1', type: 'ar ...

What is the proper method for sending parameters in JSON within a data object?

On my aspx page, I have a text box where I need to retrieve the text and pass it to a function as JSON data. To achieve this, I have a server-side method. [WebMethod] public static OfficeDetails[] BindSearchDatatable(string officename) { DataTable dt ...

Typescript validation for redundant property checks

Why am I encountering an error under the 'name' interface with an excess property when using an object literal? There is no error in the case of a class, why is this happening? export interface Analyzer { run(matches: MatchData[]): string; } ...

What could be the reason for the sudden lack of content from the Blogger API?

For weeks, I've been using the Google API to retrieve JSON data from my Blogger account and showcase and style blog posts on my personal website. Everything was functioning flawlessly until yesterday when, out of the blue, the content section stopped ...

Exploring JSON without taking into account letter case

Looking to conduct a case-insensitive search in a JSON file? Here's the JSON data you can work with: { "Data" : [ {"Name": "Widget", "Price": "25.00", "Quantity": "5" }, {"Name": "Thing", "Price": "15.00", "Quantity": "5" }, {"Nam ...

Leveraging and utilizing TypeScript npm packages

My goal is to create shared code in TypeScript, package it as an npm package, and easily install it. I attempted to create an external library like this: export class Lib { constructor(){ } getData(){ console.log('getting data from l ...

Keep the list up-to-date by adding new items promptly

Utilizing Angular 7, I have implemented the following service (Click here for StackBlitz Example): @Injectable({ providedIn: 'root' }) export class TodoService { todos: BehaviorSubject<Todo[]> = new BehaviorSubject([ { id: 1, tit ...