{"id":26154396,"url":"https://github.com/rcdmk/aspjson","last_synced_at":"2025-04-09T07:09:10.792Z","repository":{"id":3405566,"uuid":"4455651","full_name":"rcdmk/aspJSON","owner":"rcdmk","description":"A fast classic ASP JSON parser and encoder for easy JSON manipulation to work with the new JavaScript MV* libraries and frameworks.","archived":false,"fork":false,"pushed_at":"2022-10-04T05:20:08.000Z","size":217,"stargazers_count":208,"open_issues_count":6,"forks_count":89,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-04-02T05:06:53.980Z","etag":null,"topics":["asp","classic-asp","deserialization","json","serialization","utility"],"latest_commit_sha":null,"homepage":"","language":"Classic ASP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rcdmk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-05-26T15:05:52.000Z","updated_at":"2025-03-18T08:15:36.000Z","dependencies_parsed_at":"2023-01-11T16:16:47.806Z","dependency_job_id":null,"html_url":"https://github.com/rcdmk/aspJSON","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcdmk%2FaspJSON","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcdmk%2FaspJSON/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcdmk%2FaspJSON/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcdmk%2FaspJSON/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rcdmk","download_url":"https://codeload.github.com/rcdmk/aspJSON/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247994121,"owners_count":21030050,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asp","classic-asp","deserialization","json","serialization","utility"],"created_at":"2025-03-11T08:29:27.866Z","updated_at":"2025-04-09T07:09:10.768Z","avatar_url":"https://github.com/rcdmk.png","language":"Classic ASP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON object class 3.8.1\r\n## By RCDMK - rcdmk[at]hotmail[dot]com\r\n\r\n### Licence:\r\nMIT license: http://opensource.org/licenses/mit-license.php  \r\nThe MIT License (MIT)  \r\nCopyright (c) 2016 RCDMK - rcdmk[at]hotmail[dot]com  \r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  \r\n\r\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  \r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  \r\n\r\n### How to use:\r\n\r\n\u003e This lib requires LCID (Locale Code IDentifier) property of your ASP application before use.\r\n\u003e You can do this by setting the LCID in one of the following ways:\r\n\u003e * On the page declaration at the top of the page to set it to the entire page (eg.: `\u003c%@ LCID=1046 %\u003e`), OR\r\n\u003e * On the `Session` object to set it to all pages in the entire session (eg.: `Session.LCID = 1046`), OR\r\n\u003e * On the `Response` object, before using the class, to set it beyond this point on the page (eg.: `Response.LCID = 1046`)\r\n\r\n```vb\r\nResponse.LCID = 1046 ' REQUIRED! Set your LCID here (1046 = Brazilian). Could also be the LCID property of the page declaration or the Session.LCID property\r\n\r\n' instantiate the class\r\nset JSON = New JSONobject\r\n\r\n' add properties\r\nJSON.Add \"prop1\", \"someString\"\r\nJSON.Add \"prop2\", 12.3\r\nJSON.Add \"prop3\", Array(1, 2, \"three\")\r\n\r\n' remove properties\r\nJSON.Remove \"prop2\"\r\nJSON.Remove \"thisDoesNotExistsAndWillDoNothing\"\r\n\r\n' change some values\r\nJSON.Change \"prop1\", \"someOtherString\"\r\nJSON.Change \"prop4\", \"thisWillBeCreated\" ' this property doen't exists and will be created automagically\r\n\r\n' get the values\r\nResponse.Write JSON.Value(\"prop1\") \u0026 \"\u003cbr\u003e\"\r\nResponse.Write JSON.Value(\"prop2\") \u0026 \"\u003cbr\u003e\"\r\nResponse.Write JSON(\"prop3\").Serialize() \u0026 \"\u003cbr\u003e\" ' default function is equivalent to `.Value(propName)` - this property returns a JSONarray object\r\nResponse.Write JSON(\"prop4\") \u0026 \"\u003cbr\u003e\"\r\n\r\n' get the JSON formatted output\r\nDim jsonString\r\njsonString = JSON.Serialize() ' this will contain the string representation of the JSON object\r\n\r\nJSON.Write() ' this will write the output to the Response - equivalent to: Response.Write JSON.Serialize()\r\n\r\n' load and parse some JSON formatted string\r\njsonString = \"[{ \"\"strings\"\" : \"\"valorTexto\"\", \"\"numbers\"\": 123.456, \"\"arrays\"\": [1, \"\"2\"\", 3.4, [5, 6, [7, 8]]], \"\"objects\"\": { \"\"prop1\"\": \"\"outroTexto\"\", \"\"prop2\"\": [ { \"\"id\"\": 1, \"\"name\"\": \"\"item1\"\" }, { \"\"id\"\": 2, \"\"name\"\": \"\"item2\"\", \"\"teste\"\": { \"\"maisum\"\": [1, 2, 3] } } ] } }]\" ' double double quotes here because of the VBScript quotes scaping\r\n\r\nset oJSONoutput = JSON.Parse(jsonString) ' this method returns the parsed object. Arrays are parsed to JSONarray objects\r\n\r\nJSON.Write() \t\t' outputs: '{\"data\":[{\"strings\":\"valorTexto\",\"numbers\":123.456,\"arrays\":[1,\"2\",3.4,[5,6,[7,8]]],\"objects\":{\"prop1\":\"outroTexto\",\"prop2\":[{\"id\":1,\"name\":\"item1\"},{\"id\":2,\"name\":\"item2\",\"teste\":{\"maisum\":[1,2,3]}}]}}]}'\r\noJSONoutput.Write() ' outputs: '[{\"strings\":\"valorTexto\",\"numbers\":123.456,\"arrays\":[1,\"2\",3.4,[5,6,[7,8]]],\"objects\":{\"prop1\":\"outroTexto\",\"prop2\":[{\"id\":1,\"name\":\"item1\"},{\"id\":2,\"name\":\"item2\",\"teste\":{\"maisum\":[1,2,3]}}]}}]'\r\n\r\n' if the string represents an object (not an array of objects), the current object is returned so there is no need to set the return to a new variable\r\njsonString = \"{ \"\"strings\"\" : \"\"valorTexto\"\", \"\"numbers\"\": 123.456, \"\"arrays\"\": [1, \"\"2\"\", 3.4, [5, 6, [7, 8]]] }\"\r\n\r\nJSON.Parse(jsonString)\r\nJSON.Write() ' outputs: '{\"strings\":\"valorTexto\",\"numbers\":123.456,\"arrays\":[1,\"2\",3.4,[5,6,[7,8]]]}'\r\n```\r\n\t\r\nTo load records from a database:\r\n\t\r\n```vb\r\n' load records from an ADODB.Recordset\r\ndim cn, rs\r\nset cn = CreateObject(\"ADODB.Connection\")\r\ncn.Open \"yourConnectionStringGoesHere\"\r\n\r\nset rs = cn.execute(\"SELECT id, nome, valor FROM pedidos ORDER BY id ASC\")\r\n' this could also be:\r\n' set rs = CreateObject(\"ADODB.Recordset\")\r\n' rs.Open \"SELECT id, nome, valor FROM pedidos ORDER BY id ASC\", cn\t\r\n\r\nJSON.LoadRecordset rs\r\nJSONarr.LoadRecordset rs\r\n\r\nrs.Close\r\ncn.Close\r\nset rs = Nothing\r\nset cn = Nothing\r\n\r\nJSON.Write() \t\t' outputs: {\"data\":[{\"id\":1,\"nome\":\"nome 1\",\"valor\":10.99},{\"id\":2,\"nome\":\"nome 2\",\"valor\":19.1}]}\r\nJSONarr.Write() \t' outputs: [{\"id\":1,\"nome\":\"nome 1\",\"valor\":10.99},{\"id\":2,\"nome\":\"nome 2\",\"valor\":19.1}]\r\n```\r\n\t\r\nTo change the default property name (\"data\") when loading arrays and recordsets, use the `defaultPropertyName` property:\r\n\t\r\n```vb\r\nJSON.defaultPropertyName = \"CustomName\"\r\nJSON.Write() \t\t' outputs: {\"CustomName\":[{\"id\":1,\"nome\":\"nome 1\",\"valor\":10.99},{\"id\":2,\"nome\":\"nome 2\",\"valor\":19.1}]}\r\n```\r\n\t\r\nIf you want to use arrays, I have something for you too\r\n\r\n```vb\r\n' instantiate the class\r\nset JSONarr = New JSONarray\r\n\r\n' add something to the array\r\nJSONarr.Push JSON \t' Can be JSON objects, and even JSON arrays\r\nJSONarr.Push 1.25 \t' Can be numbers\r\nJSONarr.Push \"and strings too\"\r\n\r\n' write to page\r\nJSONarr.Write() ' Guess what? This does the same as the Write method from JSON object\r\n```\t\r\n\t\r\nTo loop arrays you have to access the `items` property of the `JSONarray` object and you can also access the items trough its index:\r\n\r\n```vb\r\ndim i, item\r\n\r\n\r\n' more readable loop\r\nfor each item in JSONarr.items\r\n\tif isObject(item) and typeName(item) = \"JSONobject\" then\r\n\t\titem.write()\r\n\telse\r\n\t\tresponse.write item\r\n\tend if\r\n\t\r\n\tresponse.write \"\u003cbr\u003e\"\r\nnext\r\n\r\n\r\n' faster but less readable\r\nfor i = 0 to JSONarr.length - 1\r\n\tif isObject(JSONarr(i)) then\r\n\t\tset item = JSONarr(i)\r\n\t\t\r\n\t\tif typeName(item) = \"JSONobject\" then\r\n\t\t\titem.write()\r\n\t\telse\r\n\t\t\tresponse.write item\r\n\t\tend if\r\n\telse\r\n\t\titem = JSONarr(i)\r\n\t\tresponse.write item\r\n\tend if\r\n\t\r\n\tresponse.write \"\u003cbr\u003e\"\r\nnext\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcdmk%2Faspjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frcdmk%2Faspjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcdmk%2Faspjson/lists"}