Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » JSON key name with dash (-)
JSON key name with dash (-) [message #1859515] Tue, 13 June 2023 08:13 Go to next message
Lars Udd is currently offline Lars UddFriend
Messages: 2
Registered: June 2023
Junior Member
I want to use the JSON encoder/decoder to simulate a rest API which uses JSON.
Some of the objects have keys that use a dash in the name.

For example, in ttcn I call it userData but in JSON it should be user-data.
So I tried:
variant(userData) "JSON: name as user-data";

But the compiler says:
error: in variant attribute, at or before token `-': invalid JSON token

Also tried with single quotes around user-data, but the it says that the single quote is
invalid token.

How can we work around this? We use Titan 8.3.0.
Re: JSON key name with dash (-) [message #1859523 is a reply to message #1859515] Tue, 13 June 2023 15:44 Go to previous messageGo to next message
Olaf Bergengruen is currently offline Olaf BergengruenFriend
Messages: 127
Registered: November 2018
Senior Member
Did you try:

variant(userData) "JSON:name as 'user-data'";


using single quotes?
Re: JSON key name with dash (-) [message #1859524 is a reply to message #1859523] Tue, 13 June 2023 15:49 Go to previous messageGo to next message
Olaf Bergengruen is currently offline Olaf BergengruenFriend
Messages: 127
Registered: November 2018
Senior Member
Oops, sorry, you write that you already tried my proposal (also removed the blank after the colon ?)
Re: JSON key name with dash (-) [message #1859525 is a reply to message #1859515] Tue, 13 June 2023 16:19 Go to previous messageGo to next message
Gábor Szalai is currently offline Gábor SzalaiFriend
Messages: 134
Registered: December 2015
Senior Member
Use the standard format of the attribute without JSON:

variant(userData) "name as 'user-data'";
Re: JSON key name with dash (-) [message #1859526 is a reply to message #1859524] Tue, 13 June 2023 16:21 Go to previous messageGo to next message
Adam Knapp is currently offline Adam KnappFriend
Messages: 54
Registered: November 2020
Member
Hi,
Currently, the supported syntax of the alias is the same as the syntax of an identifier in TITAN (regex: [A-Za-z][A-Za-z0-9_]*). So, the dash character is not allowed.
We will check whether we can extend this current set.
Re: JSON key name with dash (-) [message #1859527 is a reply to message #1859526] Tue, 13 June 2023 16:57 Go to previous messageGo to next message
Gábor Szalai is currently offline Gábor SzalaiFriend
Messages: 134
Registered: December 2015
Senior Member
The TITAN has two kind of "name as" attribute:
"JSON: name as identifier"
"name as 'freetext'"

The JSON encoder of the TITAN was developed before the standardization of the JSON usage in TTCN, so the attributes prefixed with "JSON:" are the old attributes. Later on the standard attributes were added to the TITAN.
The old "JSON: name as identifier" supports only identifiers, but the standardised format "name as 'freetext'" supports any kind of freetext like:
variant(type_) "name as 't  !@# 5^ --  ype'"


Re: JSON key name with dash (-) [message #1859546 is a reply to message #1859527] Wed, 14 June 2023 10:46 Go to previous message
Lars Udd is currently offline Lars UddFriend
Messages: 2
Registered: June 2023
Junior Member
Thanks for quick reply! Standard version works fine.
Previous Topic:Compiler error on in-line template as parameter of a function
Next Topic:Reference for a non-defined simpleType or complexType type: http://www.w3.org/2001/XMLSchema|anyType
Goto Forum:
  


Current Time: Mon Oct 07 05:33:04 GMT 2024

Powered by FUDForum. Page generated in 0.04600 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top