Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

How to write JSON to multi-level global?

瀏覽次數:211 次
跳到第一則未讀訊息

Сергей Каменев

未讀,
2021年11月1日 下午2:38:482021/11/1
收件者:
Hi!

Is there a ready-made M function that stores a json string as a multi-level global?

Sergey

Rod Dorman

未讀,
2021年11月1日 下午2:43:422021/11/1
收件者:
In article <9a0729bf-3f91-4fe9...@googlegroups.com>,
�еÑ гей Ð аменев <suka...@gmail.com> wrote:
>Is there a ready-made M function that stores a json string as a
>multi-level global?

There's no Standard M function that would do that.

What implementation are you running on?

--
-- Rod --
rodd(at)polylogics(dot)com

Сергей Каменев

未讀,
2021年11月1日 下午3:25:372021/11/1
收件者:
I use YottaDB.
Any M function that works well will suit me

K.S. Bhaskar

未讀,
2021年11月1日 晚上10:26:092021/11/1
收件者:
There are any number of M functions to store and retrive JSON in M global variables. Ask your favorite search engine (I used DuckDuckGo) and if you don't find links to several routines, ask again here.

Regards
– Bhaskar

Jens

未讀,
2021年11月2日 凌晨4:55:282021/11/2
收件者:
K.S. Bhaskar schrieb am Dienstag, 2. November 2021 um 03:26:09 UTC+1:
> On Monday, November 1, 2021 at 3:25:37 PM UTC-4, suka...@gmail.com wrote:
> > I use YottaDB.
> > Any M function that works well will suit me

The function at

https://github.com/lparenteau/DataBallet/blob/master/r/json.m

worked good for me...

Jens

Сергей Каменев

未讀,
2021年11月2日 清晨5:50:472021/11/2
收件者:
Thank you, Jens!

The code is pretty clear.

I found a thread with a few more options, but they are less clear.

https://groups.google.com/g/comp.lang.mumps/c/2-Figm7Uqbw

Sergey

rtweed

未讀,
2021年11月3日 上午8:59:372021/11/3
收件者:
See the mgweb_server repository at https://github.com/robtweed/mgweb-server

You can use the routines in this repo standalone. Specifically see:

https://github.com/robtweed/mgweb-server/blob/master/DEV-PATTERN.md#json-handling-made-easy

These routines for mapping arrays to/from JSON are tried and tested...and free/open source.

rtweed

未讀,
2021年11月3日 上午9:04:032021/11/3
收件者:
BTW the fact that there is a one-to-one correspondence between JSON (and XML) and M Globals is the heart of this set of documents:

https://github.com/robtweed/global_storage

and is the basis of the Node.js abstraction of Global Storage into persistent JSON/JavaScript Objects known as QEWD-JSdb:

https://github.com/robtweed/qewd-jsdb

Sam Habiel

未讀,
2021年11月4日 下午3:19:562021/11/4
收件者:

Valeriu Gontia

未讀,
2021年11月11日 清晨7:20:172021/11/11
收件者:
четверг, 4 ноября 2021 г. в 21:19:56 UTC+2, Sam Habiel:
Hello Sam !
Why, if numbers appear in a node, I get a different result ???

In the same example:
S X ("myObj", "booleanT") = "true"
S X ("myObj", "booleanF") = "false"
S X ("myObj", "numeric") = 3.1416
S X ("myObj", "nullValue") = "null"
S X ("myObj", "array", 1) = "one"
S X ("myObj", "array", 2) = "two"
S X ("myObj", "array", 3) = "three"
S X ("myObj", "subObject", "fieldA") = "hello"
S X ("myObj", "subObject", "fieldB") = "world"
JSON (1) = "{" myObj ": {" array ": [" one "," two "," three "]," booleanF ": false," booleanT ": true," nullValue ": null," numeric ":"
JSON (2) = "3.1416," subObject ": {" fieldA ":" hello "," fieldB ":" world "}}}"

In my case:
XX (501, "array", 1) = "one"
XX (501, "array", 2) = "two"
XX (501, "array", 3) = "three"
XX (501, "booleanF") = "false"
XX (501, "booleanT") = "true"
XX (501, "nullValue") = "null"
XX (501, "numeric") = 3.1416
XX (501, "subObject", "fieldA") = "hello"
XX (501, "subObject", "fieldB") = "world"
JSON (1) = "{[{" array ": [" one "," two "," three "]," booleanF ": false," booleanT ": true," nullValue ": null," numeric ": 3.1416 , "
JSON (2) = "" subObject ": {" fieldA ":" hello "," fieldB ":" world "}}]}"

It happens to me that the nodes of globals contain only numbers
(codes) ...

Sam Habiel

未讀,
2021年11月11日 上午9:49:312021/11/11
收件者:
The encoder behaves differently if you start with a number (it assumes you want an array) vs not (it will assume that you want an object).

--Sam

Valeriu Gontia

未讀,
2021年11月11日 下午1:17:392021/11/11
收件者:
четверг, 11 ноября 2021 г. в 16:49:31 UTC+2, Sam Habiel:
I'm testing a Rob Tweed encoder
Get a different result:
s aa = $$ arrayToJSON ^% zewdJSON ("XX")
aa="{"501":{"array":["one","two","three"],"booleanF":false,"booleanT":true,"nullValue":"null","numeric":3.1416,"subObject":{"fieldA":"hello","fieldB":"world"}}}"

Valeriu Gontia

未讀,
2021年11月12日 凌晨2:02:022021/11/12
收件者:
четверг, 11 ноября 2021 г. в 20:17:39 UTC+2, Valeriu Gontia:
I get the same results Rob Tweed and Winfried Bantel encoder:
XX(501,8924)="true"
XX(501,8925)="false"
XX(501,8926)=3.1416
XX(501,8927)="null"
XX(501,8928,1)="one"
XX(501,8928,2)="two"
XX(501,8928,3)="three"
XX(501,8929,222)="hello"
XX(501,8929,333)="world"
aa="{"501":{"8924":true,"8925":false,"8926":3.1416,"8927":"null","8928":["one","two","three"],"8929":{"222":"hello","333":"world"}}}"
bb="{"501":{"8924":"true","8925":"false","8926":3.1416,"8927":"null","8928":{"1":"one","2":"two","3":"three"},"8929":{"222":"hello","333":"world"}}}"

Sam, i like your approach of splitting the JSON into a one-dimensional array. Ultimately, I can pass a large amount of data to the client in a loop. But this doesn't fit the structure of my globals.
As I showed above, this suits me for my globals. But, here the function returns a string that does not exceed 32 KB, that is, i am limited in transferring data to the client.

rtweed

未讀,
2021年11月12日 上午8:14:402021/11/12
收件者:
What were you expecting the JSON representation of your Global contents to be? My encoder is producing exactly what I'd have expected

Rob

Valeriu Gontia

未讀,
2021年11月12日 上午8:35:452021/11/12
收件者:
пятница, 12 ноября 2021 г. в 15:14:40 UTC+2, rtweed:
> What were you expecting the JSON representation of your Global contents to be? My encoder is producing exactly what I'd have expected
>
> Rob
There are cases in old M implementations when it is necessary to return more than 32 kb to the JSON client
Your decoder is fine, but it returns the maximum line error.
CADRE> d arrayToJSON^%zmgwebUtils ("^CAD")

... ... ... s json = json_value_ ","
^
<MAXSTRING> walkArray + 51 ^% zmgwebUtils

CADRE 15d5>

Sam has everything OK, but the structure is not like yours.
CADRE> d encode ^%zwebjsonEncode ("^CAD","JSON")

CADRE>

rtweed

未讀,
2021年11月12日 上午9:26:032021/11/12
收件者:
You can always reconfigure your M system to increase the maximum size allowed for data. Of course there's also the maximum combined global subscript length issue that can limit JSON to/from global mapping. A good alternative is to use the DOM APIs to map JSON. These are implemented in my EWD source code (see my EWD repo on Github) and in QEWD (implemented as JavaScript APIs). See:

https://github.com/robtweed/global_storage/blob/master/XML_DB.md
https://github.com/robtweed/qewd-jsdb/blob/master/DOM.md (the last sections deal with JSON mapping using the DOM)

Rob
0 則新訊息