[plugin] JSON (import/export/generate/edit/inspect/...)

0 favourites
From the Asset Store
The I18N (Translation) is a Construct plugin created to translate text in game.
  • mfdeveloper

    I'm not using construct that much these days. But if I remember correctly the plugin has something like

    LoadJSON "{""name"": ""test"", ""age"",""xxx""}" at root@'some','kind','of','path'[/code:iu5f956j]
    which would exactly achieve what you described without having some nasty parsing. Something like[code:iu5f956j]Set Value "{o_o}" at root@ 'smilies','0'[/code:iu5f956j] should be expected to work
    
    has for sharing things on github, yeah, I should, three years ago I wasn't really using it that much so I didn't have this reflex.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi. When I try to load json data from AJAX.LastData I get this error:

    Javascript error!

    invalid character

    http://myIP/JSON_plugin.js, line 472 (col 9)

    this is the data from AJAX.Last Data:

    test({"realms":[{"type":"rp","population":"medium","queue":false,"wintergrasp":{"area":1,"controlling-faction":1,"status":0,"next":1462710723426},"tol-barad":{"area":21,"controlling-faction":0,"status":0,"next":1462709800605},"status":true,"name":"Zirkel des Cenarius","slug":"zirkel-des-cenarius","battlegroup":"Embuscade / Hinterhalt","locale":"de_DE","timezone":"Europe/Paris","connected_realms":["zirkel-des-cenarius","todeswache"]}]});

    OR:

    {"realms":[{"type":"rp","population":"medium","queue":false,"wintergrasp":{"area":1,"controlling-faction":1,"status":0,"next":1462710723768},"tol-barad":{"area":21,"controlling-faction":0,"status":1,"next":1462710700949},"status":true,"name":"Zirkel des Cenarius","slug":"zirkel-des-cenarius","battlegroup":"Embuscade / Hinterhalt","locale":"de_DE","timezone":"Europe/Paris","connected_realms":["zirkel-des-cenarius","todeswache"]}]}

    what invalid character?

    even if I remove "({"realms":" at the start and "});" at the end I get an error.

  • Bl4ckSh33p

    I see no problem here

    make sure you load a proper JSON string.

    Good test is to copy paste the exact input you try to load in http://jsonlint.com and see if it's a valid string.

    for example

    {"realms": []}[/code:15yo6a9a] is a valid json string, but [code:15yo6a9a]test({"realms": []})[/code:15yo6a9a]is obviously not.
  • Hello Yann,

    Has there been any new development, or syntax cleanups for this plugin ?

    This looks promising

    Hugo

  • Hi,

    Is it possible to delete an element of an array? Currently, what I've tried so far is that I can delete an element of an object, but not array. When I use "delete" action and set the keys into an array, it just emptied the array, making it null. What matter is when I try to get the size (eg: JSON.Size(0, "data"), the null elements are counted as well. Can I delete the element entirely so it wont be counted? Or am I doing it wrong?

    Regards,

    Alvin

  • So I create a fix for myself. Now it is able to delete an element of an array.

    Say we have JSON like this:

    {"models":[{"id":1,"type":"Type 0"},{"id":2,"type":"Type 1"}]}[/code:1ip9crp5]
    Previously, if I set action:
    [code:1ip9crp5]delete root@"models", 0[/code:1ip9crp5]
    The result will be like this: (Note that the first element becomes [i]null[/i].)
    [code:1ip9crp5]{"models":[null,{"id":2,"type":"Type 1"}]}[/code:1ip9crp5]
    
    So I change the runtime.js at line 405, from this:
    [code:1ip9crp5]function deleteIfValid(obj,prop) {
    	if ( obj !== undefined && obj !== null && 
    		(typeof obj === "object") && obj[prop] !== undefined){
                    
    		delete obj[prop];
    	} else {
    		log("invalid path: root@"+ path_.toString(),"warn");
    	}
    }[/code:1ip9crp5]
    Into this:
    [code:1ip9crp5]function deleteIfValid(obj,prop) {
    
    	if ( obj !== undefined && obj !== null && obj[prop] !== undefined ) {
    
    		if( Object.prototype.toString.call( obj ) === '[object Array]' ) {				// If object is an element of an array
    			obj.splice(prop,1);															// delete element at index prop
    		} else if( Object.prototype.toString.call( obj ) === '[object Object]' ) {		// If object is an object
    			delete obj[prop];
    		}
    
    	} else {
    		log("invalid path: root@"+ path_.toString(),"warn");
    	}
    }[/code:1ip9crp5]
  • hlebegue tmntppn

    yeah I knew about this bug, but years ago, I started a new interesting feature and I lost interest in C2.... :D....

    so I never released a new version (at that time I was so n00b I wasn't using version control so my fix was mixed with my new feature in progress...)

    Anyway, yeah that's basically the fix. I think I'll try to release the fix with that new feature some day.... Work is eating up any will to do anything personal so well... (:

  • Yann

    Great plugins tho. I've been using it in some of my projects and it helps a lot, so thx for the plugins.

    Feature suggestion: Find indexof("value"). Is it possible to add a feature to find index in an array? Similar to indexof expression in Array object. What I'm doing now is loop through each element and compare its value one by one. Indexof will make a shorter line of code.

  • tmntppn

    yeah, the problem is that if I start adding indexOf, I'll have to add push, pop and shift, unshift etc... the plugin will quickly turn into an array plugin.

    And also people might want something like that for object (keyOf, etc)...

    Well... I'll think about it but since I'm not as motivated as when I started it, because I'm not using c2 anymore, the more feature I'll implement, the higher the risk of bug there will be, and I'd like not to have to spend too much time in maintaining it (:

  • I will continue improve my rex_hash plugin, or Yann might entrust this Json plugin to someone who can maintain it.

  • After more than 2 years I finally released a new version :D....

    Now everything is hosted on github including the documentation

    I'll edit my first post to reflect that.

  • I'm so sorry for my late response @Yann

    Many thnks , you are right! The action

    LoadJson[/code:6gqwu316] works correctly. I tried use [code:6gqwu316]SetValue[/code:6gqwu316] method because it is more clear for me.
    
    Ahhh I saw that you share this plugin on [b]github[/b], it is fuckying awesome. Thank you so much to share and accept new changes
  • We met a issue after updated to V1.2 that chrome log error at "logInvalidPath" if we didn't Commented it

  • totoyan

    share a capx with a case that reproduce the bug, so I know if it comes form the plugin, or a misuse of it

    if it's a bug from the plugin, I should be able to quickly patch it =)

  • Yann is still supporting this plugin? I know rexrainbow is hesitant about supporting his rex-hash. We might try to migrate to your plugin for all of our JSON stuff pending testing it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)