• How to write JSON to multi-level global?

    From =?UTF-8?B?0KHQtdGA0LPQtdC5INCa0LDQv@21:1/5 to All on Mon Nov 1 11:38:47 2021
    Hi!

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

    Sergey

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rod Dorman@21:1/5 to sukamenev@gmail.com on Mon Nov 1 18:43:41 2021
    In article <9a0729bf-3f91-4fe9-91a7-4d05df3b0e8dn@googlegroups.com>,
    е гей аменев <sukamenev@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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?B?0KHQtdGA0LPQtdC5INCa0LDQv@21:1/5 to All on Mon Nov 1 12:25:35 2021
    I use YottaDB.
    Any M function that works well will suit me

    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From K.S. Bhaskar@21:1/5 to suka...@gmail.com on Mon Nov 1 19:26:08 2021
    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
    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?

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jens@21:1/5 to K.S. Bhaskar on Tue Nov 2 01:55:27 2021
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?B?0KHQtdGA0LPQtdC5INCa0LDQv@21:1/5 to All on Tue Nov 2 02:50:46 2021
    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

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rtweed@21:1/5 to All on Wed Nov 3 05:59:35 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rtweed@21:1/5 to All on Wed Nov 3 06:04:02 2021
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Sam Habiel@21:1/5 to rtweed on Thu Nov 4 12:19:55 2021
    On Wednesday, November 3, 2021 at 7:04:03 AM UTC-6, rtweed wrote:
    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
    You can try this too: https://github.com/shabiel/M-Web-Server/blob/master/doc/important-utilities.md#json

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Valeriu Gontia@21:1/5 to All on Thu Nov 11 04:20:16 2021
    четверг, 4 ноября 2021 г. в 21:19:56 UTC+2, Sam Habiel:
    On Wednesday, November 3, 2021 at 7:04:03 AM UTC-6, rtweed wrote:
    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
    You can try this too: https://github.com/shabiel/M-Web-Server/blob/master/doc/important-utilities.md#json

    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) ...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Sam Habiel@21:1/5 to gont...@gmail.com on Thu Nov 11 06:49:30 2021
    On Thursday, November 11, 2021 at 5:20:17 AM UTC-7, gont...@gmail.com wrote:
    четверг, 4 ноября 2021 г. в 21:19:56 UTC+2, Sam Habiel:
    On Wednesday, November 3, 2021 at 7:04:03 AM UTC-6, rtweed wrote:
    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
    You can try this too: https://github.com/shabiel/M-Web-Server/blob/master/doc/important-utilities.md#json
    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) ...
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Valeriu Gontia@21:1/5 to All on Thu Nov 11 10:17:36 2021
    четверг, 11 ноября 2021 г. в 16:49:31 UTC+2, Sam Habiel:
    On Thursday, November 11, 2021 at 5:20:17 AM UTC-7, gont...@gmail.com wrote:
    четверг, 4 ноября 2021 г. в 21:19:56 UTC+2, Sam Habiel:
    On Wednesday, November 3, 2021 at 7:04:03 AM UTC-6, rtweed wrote:
    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
    You can try this too: https://github.com/shabiel/M-Web-Server/blob/master/doc/important-utilities.md#json
    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) ...
    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

    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"}}}"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Valeriu Gontia@21:1/5 to All on Thu Nov 11 23:02:01 2021
    четверг, 11 ноября 2021 г. в 20:17:39 UTC+2, Valeriu Gontia:
    четверг, 11 ноября 2021 г. в 16:49:31 UTC+2, Sam Habiel:
    On Thursday, November 11, 2021 at 5:20:17 AM UTC-7, gont...@gmail.com wrote:
    четверг, 4 ноября 2021 г. в 21:19:56 UTC+2, Sam Habiel:
    On Wednesday, November 3, 2021 at 7:04:03 AM UTC-6, rtweed wrote:
    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
    You can try this too: https://github.com/shabiel/M-Web-Server/blob/master/doc/important-utilities.md#json
    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) ...
    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
    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"}}}"

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rtweed@21:1/5 to All on Fri Nov 12 05:14:39 2021
    What were you expecting the JSON representation of your Global contents to be? My encoder is producing exactly what I'd have expected

    Rob

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Valeriu Gontia@21:1/5 to All on Fri Nov 12 05:35:44 2021
    пятница, 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>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rtweed@21:1/5 to All on Fri Nov 12 06:26:02 2021
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)