[PLUGIN] Load JSON

Post your completed addons to share with the community

Post » Wed Mar 21, 2012 10:27 pm

Hi,
this plugin can load and parse a JSON-file. It can be used for translation of words or phrases - written in an external json-file. The "funny characters" in the demo-JSON-file are unicode characters.


Because it loads a custom json-file this plugin doesn't work in preview mode.

____________________________
Update v 1.2
Bugfix - getting entries of keys

Demo+Plugin+JSON-file v 1.2. (capx for C2 r85)
(second test with fewer keys)

____________________________
Update v 1.1
Demo+Plugin+JSON-file v 1.1. (capx for C2 r85)

Two more expressions:
1) getRootKeysSize --> return number
Returns an integer how many keys exists in the JSON-file.
2) getKeySize(stringKey) --> return number
Returns an integer how many entries exist at the key- stringKey.

How to use --> screenshots in my post below
____________________________


Demo+Plugin+Example (v 1.0)


Property:
The name of the json-file. [optional path if the file is not located next to the exported index.html]


Condition:


Action:


Expressions:
getData(keyWordAsText,positionAsNumber) --> returns Text
eg json-data is: "dog": ["Dog", "Cane"]
getData("dog",0) --> returns "Dog"
getData("dog",1) --> returns "Cane"

readLoadingReturn --> returns Text
show the status of loading: word is found, not found, success, error,..


How to use the plugin - overview:


All suggestions are welcome and have fun,
Joe7Joe72012-04-04 17:30:27
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Thu Mar 22, 2012 7:26 am

I had made a similar plugin named Hash table before.

However, your plugin seems more directly.rexrainbow2012-03-22 07:29:57
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Thu Mar 22, 2012 7:28 pm

@rexrainbow: I know your plugin since it was available . I have also used JSON-loading with c2 before - but with pure (external) Javascript(-hashtables). Yesterday I've read about a language discussion and so I've decided to make a Plugin for "a simple loading" a "simple JSON-Langugage-file".Joe72012-03-22 19:30:04
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Thu Mar 22, 2012 11:16 pm

This is really good!
Can your plugin handle nested values/multi-dimensional arrays?
B
35
S
8
G
8
Posts: 532
Reputation: 6,868

Post » Sat Mar 24, 2012 8:50 pm

No.. it's only for simple json. Do we really need support for nested json-structures? I ask because I suppose that the users that use json for complicated savings or readings use php or pure javascript because of the flexibility and time to parse. If I would try to extend this plugin I think it would slow down the reading-time for simple files too. I have an idea how to implement nested things as a plugin but I'm still not sure if anyone will use it or needs it.. Joe72012-03-24 21:03:13
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Mon Mar 26, 2012 2:10 am

I would welcome it, though the better option would be something native (hint @Ashley).
If I were to make such a plugin, I'd implement it like a jQuery selector (to get around the expression limitations), such as getStringVal("object.value.array[key].anothervalue") and complementary operations, such as getNumberVal and getBoolVal
B
35
S
8
G
8
Posts: 532
Reputation: 6,868

Post » Mon Mar 26, 2012 1:23 pm

@Fimbul Great. Better idea than mine.
I thought at key1.key2.key3 but jquery syntax is much better. I'll try it but in the next days I've no time.. so if it's really important feel free to fork or change the plugin by yourself. I'look at it asap..   Joe72012-03-26 13:28:49
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Tue Apr 03, 2012 2:36 pm

Great plugin! Keep up the good work!

Is there a way to count the number of words in the JSON file? I'd like to run a foreach loop that changes, depending on the contents of the JSON file. Also, can I put Construct 2 variables in the JSON URL (ex. to send parameters to a PHP file in order to create the correct JSON file?

Thanks in advance. I really appreciate it. This is just what I've been looking for! :)
B
12
S
3
G
4
Posts: 55
Reputation: 3,186

Post » Tue Apr 03, 2012 2:45 pm

No, counting isn't possible this time. Update is on the way.
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Tue Apr 03, 2012 7:34 pm

@tnewhook

Now with version 1.1 counting is possible.
Two more expressions:
Get the number of keys:


Get the numbers of entries of a given key:


short overview:
Joe72012-04-03 19:38:59
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Next

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 5 guests