Jump to content




JSON API v2.0.1 for ComputerCraft


54 replies to this topic

#21 ElvishJerricco

  • Members
  • 803 posts

Posted 21 June 2014 - 09:48 AM

View Postdaphee, on 20 June 2014 - 04:09 PM, said:

Thank you for this nice lib. I've used it successfully on numerous projects.
This time it fails to decode this string
{"success":true,"code":0,"error":"","data":{"clientId":"testClient","requestId":"1","data":{"method":"get_redstone","side":"right"}}}
It fails with "json:167: attempt to index ? (a nil value)"

Fixed it! The issue was the empty string. It failed to handle that properly. Not sure why the pattern I used before didn't work with it but the new one does.

Edited by ElvishJerricco, 21 June 2014 - 09:48 AM.


#22 daphee

  • Members
  • 8 posts
  • LocationGermany

Posted 22 June 2014 - 07:32 PM

Great! Thanks!

#23 NightmareInfinity

  • New Members
  • 2 posts

Posted 26 March 2015 - 04:00 PM

is there a way to get the compact json from a website that is compacted and save it as a pretty string?

#24 ElvishJerricco

  • Members
  • 803 posts

Posted 26 March 2015 - 08:24 PM

View PostNightmareInfinity, on 26 March 2015 - 04:00 PM, said:

is there a way to get the compact json from a website that is compacted and save it as a pretty string?

There's no straight conversion function, but you could do json.encodePretty(json.decode(str))

#25 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 03 May 2015 - 08:02 PM

For your records, Hive is now using this for it's github updating.

I hope you are ok with us redistributing your code,

Edited by Lupus590, 03 May 2015 - 08:03 PM.


#26 NightmareInfinity

  • New Members
  • 2 posts

Posted 22 May 2015 - 05:26 PM

View PostElvishJerricco, on 26 March 2015 - 08:24 PM, said:

View PostNightmareInfinity, on 26 March 2015 - 04:00 PM, said:

is there a way to get the compact json from a website that is compacted and save it as a pretty string?

There's no straight conversion function, but you could do json.encodePretty(json.decode(str))
Im so dumb. I couldn't figure that out :P

#27 flaghacker

  • Members
  • 655 posts

Posted 23 May 2015 - 02:12 PM

Looks neat, and your code is really clean. One little mistake, your forgot to close the file in your decodeFromFile function.

#28 manu_03

  • Members
  • 84 posts
  • LocationSpain

Posted 28 July 2015 - 11:46 AM

Is that OK if I use it in MocOS installer and implement it within the internal APIs?

#29 Stekeblad

  • Members
  • 62 posts
  • LocationSweden

Posted 14 January 2016 - 02:50 PM

I am using this very useful API in my program FluxedSeeds to decode the json file I download from gitHub

#30 Pyuu

  • Members
  • 203 posts

Posted 07 February 2016 - 03:34 AM

This API breaks when you do something like:
{
"Version": "1.0"
}

But works when:
{"Version": "1.0"}

Annoying for formatting.
Also, as a bug report from my OS (in which I'm heavily utilizing JSON), json.decodeFromFile doesn't close the file handle and causes unpredictable bugs.

Also, as another bug: You cannot JSON encode a string that contains the JSON api. Why? Because:
local controls = {["\n"]="\\n", ["\r"]="\\r", ["\t"]="\\t", ["\b"]="\\b", ["\f"]="\\f", ["\""]="\\\"", ["\\"]="\\\\"}

Turns into:
local controls = {["\
"]="\\
", ["\
"]="\\
", ["\ "]="\\ ", ["\"]="\\", [""]="\", ["\""]="\\\"", ["\\"]="\\\\"}

One way to get around this is to convert entire files to hexadecimal before Encode/decode.

Edited by Mayushii, 07 February 2016 - 05:06 AM.


#31 ElvishJerricco

  • Members
  • 803 posts

Posted 14 February 2016 - 07:02 PM

I cannot replicate the first problem.

The second is caused by some really lazy string handling on my part. You really shouldn't be transferring code in Json but that's beside the point =P What I wrote works for any normal use case of json, but for something like this it broke. I'll get to fixing it.

#32 ElvishJerricco

  • Members
  • 803 posts

Posted 14 February 2016 - 07:26 PM

Fixed. Let me know if issues persist.

#33 kd8lvt

  • Members
  • 12 posts

Posted 15 February 2016 - 04:43 PM

Hello! My Twitch.tv interfacing api depends on your JSON api, and it really is great and easy to use, however, with the newest version of your api, whenever a new computer downloads the JSON api (I have it auto downloading from your pastebin) the computer locks up, then reboots. No error message, and it has no reason to do it either, it seems. So, for now I am reuploading an older version while I hope and pray that this magically gets fixed. I'm sorry I can't provide more details on the matter other than "the computer locks up, then reboots". If I could, I would.
Thanks!
~Kd
[Edit] I am using json.decode, if that helps.

Edited by kd8lvt, 15 February 2016 - 04:44 PM.


#34 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 15 February 2016 - 04:53 PM

View Postkd8lvt, on 15 February 2016 - 04:43 PM, said:

Hello! My Twitch.tv interfacing api depends on your JSON api, and it really is great and easy to use, however, with the newest version of your api, whenever a new computer downloads the JSON api (I have it auto downloading from your pastebin) the computer locks up, then reboots. No error message, and it has no reason to do it either, it seems. So, for now I am reuploading an older version while I hope and pray that this magically gets fixed. I'm sorry I can't provide more details on the matter other than "the computer locks up, then reboots". If I could, I would.
Thanks!
~Kd
[Edit] I am using json.decode, if that helps.

it's possible that the pastebin change has caused this problem. Show us your download script.

#35 ElvishJerricco

  • Members
  • 803 posts

Posted 15 February 2016 - 09:44 PM

View Postkd8lvt, on 15 February 2016 - 04:43 PM, said:

Hello! My Twitch.tv interfacing api depends on your JSON api, and it really is great and easy to use, however, with the newest version of your api, whenever a new computer downloads the JSON api (I have it auto downloading from your pastebin) the computer locks up, then reboots. No error message, and it has no reason to do it either, it seems. So, for now I am reuploading an older version while I hope and pray that this magically gets fixed. I'm sorry I can't provide more details on the matter other than "the computer locks up, then reboots". If I could, I would.
Thanks!
~Kd
[Edit] I am using json.decode, if that helps.

Weird. Worked when I tested it. But I only tested it with the C, command line version of Lua. Didn't try it in Minecraft.

#36 ElvishJerricco

  • Members
  • 803 posts

Posted 15 February 2016 - 09:53 PM

Got it. Somehow my testing didn't reveal a flaw in the string parsing. Fixed now.

#37 Gumball

  • Members
  • 254 posts
  • LocationFairbanks, Alaska

Posted 21 June 2016 - 03:43 AM

May I use this in one of my projects? It's basically a bridge between MySQL querying and CCLua, and it outputs your query's rows as JSON, and I was wondering if I could put it directly into my program

#38 Gumball

  • Members
  • 254 posts
  • LocationFairbanks, Alaska

Posted 21 June 2016 - 04:30 AM

For now I will probably just give a link to this topic, so that I do not distribute your program directly.

#39 Steampunk_Sam

  • New Members
  • 1 posts

Posted 17 November 2016 - 04:13 PM

Hello,
This API is a fantastic addition for CC and I have started using it alongside my webserver for cross-game data transfer,

However I am running into a "Invalid escape character" error when it tries to parse the following:

{
    "status": true,
    "file": {
	    "name": "MC_chat",
	    "created_at": "2016-11-17 16:08:19",
	    "created_by": "N\/A",
	    "private": "0",
	    "rows": [
		    {
			    "text": "hello",
			    "created_at": "2016-11-17 17:11:49",
			    "created_by": "N\/A"
		    }
	    ]
    }
}

Any help would be much appreciated, I can also supply you (in private) usable links to my web api that I am retrieving the json string from for testing purposes.

Skype: SammyT291
Im always sitting in TeamSpeak at ts.wizry.net

All the best,
Sam.

#40 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 17 November 2016 - 09:36 PM

View PostSteampunk_Sam, on 17 November 2016 - 04:13 PM, said:

-snip-

The API doesn't support "\/" as an escape character. If you add decodeControls["\\/"] = "/" on line 95 then everything should decode correctly.

Edited by SquidDev, 17 November 2016 - 09:36 PM.






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users