Hi,
There is a mode setting for JBUILD() that converts numeric strings to numbers but nothing to go in the reverse direction converting numbers to quoted strings.
You would need to ensure that the item in the data collection is a string. The following quick example shows one way to do this…
c = collection()
c{'a'} = 123 ;* Save as number
c{'b'} = str(123) ;* Save as string
display jbuild(c)
Martin
From: ope...@googlegroups.com <ope...@googlegroups.com>
On Behalf Of jaya...@gmail.com
Sent: 07 March 2022 03:18
To: OpenQM <ope...@googlegroups.com>
Subject: JBUILD modes and additive values in QM
EXTERNAL EMAIL |
--
You received this message because you are subscribed to the Google Groups "OpenQM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
openqm+un...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/openqm/1f734913-e51a-4e41-8bb5-a0c58cb7d26dn%40googlegroups.com.
================================
Rocket Software, Inc. and subsidiaries ■ 77 Fourth Avenue, Waltham MA 02451 ■ Main Office Toll Free Number: +1 855.577.4323
Contact Customer Support: https://my.rocketsoftware.com/RocketCommunity/RCEmailSupport
Unsubscribe from Marketing Messages/Manage Your Subscription Preferences - http://www.rocketsoftware.com/manage-your-email-preferences
Privacy Policy - http://www.rocketsoftware.com/company/legal/privacy-policy
================================
This communication and any attachments may contain confidential information of Rocket Software, Inc. All unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify Rocket Software immediately and destroy
all copies of this communication. Thank you.
I mis-read the original email in this thread so my previous response did not resolve the problem.
JBUILD() normally uses the data type of the variables in the data collection to determine the JSON data type. If you have, for example, statement such as
A = DYN<1>
where DYN is a dynamic array with field 1 containing a numeric value, variable A will be a string because field extraction is defined as returning a sting value. The program may go on to do arithmetic operations on this variable and the data type conversion needed will occur automatically as multivalue Basic uses type variant variables.
If you want the numeric value to be a number, the traditional way to convert a numeric string to a number is the rather odd
A = DYN<1> + 0
QMBasic provides explicit type conversion functions that make this a bit clearer.
A = NUMERIC(DYN<1>)
You could use this construct when saving numeric values in elements of a data collection but, if the JSON representation of your data collection is to treat all numeric strings as numbers, you can do
JSON.STRING = JBUILD(COL, JB$NUM)
The JB$NUM token is defined in the KEYS.H include record.
Martin
From: ope...@googlegroups.com <ope...@googlegroups.com>
On Behalf Of jaya...@gmail.com
Sent: 07 March 2022 03:18
To: OpenQM <ope...@googlegroups.com>
Subject: JBUILD modes and additive values in QM
EXTERNAL EMAIL |
--
You received this message because you are subscribed to the Google Groups "OpenQM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
openqm+un...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/openqm/1f734913-e51a-4e41-8bb5-a0c58cb7d26dn%40googlegroups.com.