Menu

first-name keeps the hyphen in the draft
📰

first-name keeps the hyphen in the draft

DEV Community: laravel·Ameen Usman·about 3 hours ago
#stNtu8ki
#devtolaravel#devto#dev#name#first
Reading 0:00
15s threshold

A key named first-name looks fine in JSON. The drafts do not treat it the same way. On the JSON converter , Laravel quotes it and stays valid. TypeScript and the PHP DTO keep the hyphen in the identifier. Conversion runs in the browser. Nothing is uploaded.

The sample

{ "first-name" : "Ada" , "role" : "engineer" }

Enter fullscreen mode

Exit fullscreen mode

Laravel prints valid array syntax: 'first-name' => 'Ada' . TypeScript emits first-name: string; . The PHP DTO emits public string $first-name; and the constructor uses the same name. The class stays DataTransferObject .

That is a draft, not production code. Rename the field before you ship if the hyphen is not legal in your language.

Keep this separate from other mistakes

A trailing comma such as {"a":1,} clears every format. That is a parse error, not a hyphen problem. Repair broken text in the JSON formatter , then convert again.

A nested object under meta becomes interface Meta in TypeScript and public array $meta on the PHP class.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.