Author Topic: Jettison (JSON Parser, v3.0.1) + Jettison-Circuit (JSON networking)  (Read 3363 times)

Repository: https://github.com/portify/jettison
Download: https://github.com/portify/jettison/archive/master.zip
Clone: https://github.com/portify/jettison.git

Jettison (v3.0.1)

Jettison is a simple JSON parser in TorqueScript, which should be standards-compliant in terms of JSON syntax and data types (supports null, bool, number, string, hash, array).
It can parse (into TS strings and objects), manipulate (editing parsed objects) and serialize (dump to JSON) arbitrary JSON data.

How simple?

%json = parseJSON("...");
if (%json $= "") return error("parsing failed");
// ...
if (isJSONObject(%json)) %json.delete();


Null, booleans, numbers and strings are represented as you might expect.
Hashes and arrays are custom objects with simple access to the data they contain.

For the given JSON:

[
  {
    "id": 6693533,
    "name": "jettison",
    "full_name": "portify/jettison",
    "owner": {
      "login": "portify",
      "id": 1732901,
      ...
    },
    "private": false,
    "html_url": "https://github.com/portify/jettison",
    "description": "A JSON parser written in TorqueScript.",
    "fork": false,
    "url": "https://api.github.com/repos/portify/jettison",
    ...
    "size": 284,
    "stargazers_count": 1,
    "watchers_count": 1,
    "language": "C#",
    "has_issues": true,
    "has_downloads": true,
    "has_wiki": true,
    "forks_count": 0,
    "mirror_url": null,
    "open_issues_count": 1,
    "forks": 0,
    "open_issues": 1,
    "watchers": 1,
    "default_branch": "master",
    "master_branch": "master"
  },
  ...
]


It can be manipulated in the following way:

==>$j = parseJSON("...");
==>echo($j.item[0].description);
A JSON parser written in TorqueScript.
==>echo($j.item[0].owner.login);
portify
==>echo("GitHub" SPC ($j.item[0].has_wiki ? "is" : "is not") SPC "lying!");
GitHub is lying!


Autogenerated documentation


does this still throw an error when you input
{
"test":"whatever",
"asdf":"asdfasfs",
}

yes because that's invalid JSON


I find it amusing that the Blockland forums are often the top result when I google "TorqueScript [insert design problem here]".

Much thanks, Port! :D

BLF Coding help is literally the most comprehensive resource for torquestuff on the entire internet.

Garage Games might Annoying Orange us for general Torque game engine help, but yeah...

I have to say Port this is really good, only problem is, I'm rubbish at coding servers.

I have to say Port this is really good, only problem is, I'm rubbish at coding servers.
What?


Pacnet was coding the servers, I am coding the client.
How is that relevant to this topic?

How is that relevant to this topic?
Here's an easy answer: it isn't