EasyJSON

We are glad to present you EasyJSON**,** bringing the power of JSON serialization and deserialization to Unity 3.5+ (both Free and Pro).

AVAILABLE ON THE ASSET STORE

EasyJSON allows you, thanks to only two functions, to serialize and deserialize any object you want including some built-in classes of Unity (Vector3, Color…). Also some extension methods have been added in order to use the features of EasyJSON directly from a string or WWW object.

This asset also allows you to generate compressed JSON string (no space, no line break) for saving bandwidth or pretty JSON string (with identations and line breaks) that can be easily readable by people.

It was successfully tested on every platform supported by Unity, including Windows Phone application.

We wanted to make EasyJSON as easy as possible in order to let people without any programming skills to use all the power of JSON for exchanging data between applications or servers. Indeed, no programming skill is required, EasyJSON is very handy.

You can check how easy it is to use this asset by checking the documentation and all available functions here:
http://www.takohi.com/data/unity/assets/easyjson/documentation/

The price: 2$.
The asset is available on the asset store here.

If you have any suggestion or any question, please feel free to ask!

Here is a code example showing how EasyJSON can be used:

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using EasyJSON;

public class EasyJSONExample : MonoBehaviour {

    IEnumerator Start () {

        // Let's construct our entity
        Box box = new Box();
        box.dimension = new Vector3(2f, 1.5f, 3f);

        Product product1 = new Product();
        product1.name = "Cheese";
        product1.description = "Cheese made by a firefighter from Boston, Texas.";
        product1.price = 9.99f;
        box.products.Add(product1);

        Product product2 = new Product();
        product2.name = "Ham";
        product2.description = "Ham from Tokyo, Argentina.";
        product2.price = 69.69f;
        box.products.Add(product2);

        Product product3 = new Product();
        product3.name = "Bread";
        product3.description = "Bread gently cooked by your mother.";
        product3.price = 13.31f;
        box.products.Add(product3);

        // Serialize the entity into a JSON string
        string output = Serializer.Serialize<Box>(box);
        Debug.Log("Compressed Json:\n" + output);

        string prettyOutput = Serializer.Serialize<Box>(box, true);
        Debug.Log("Pretty Json:\n" + prettyOutput);

        // Now we deserialize the JSON string to construct the entity
        Box deserializedBox = Serializer.Deserialize<Box>(output);
        // or Box deserializedBox = output.Deserialize<Box>();

        Debug.Log(string.Format("Box with {0} product(s) and dimension {1}.", deserializedBox.quantity, deserializedBox.dimension));

        // We can also deserialize a JSON string directly from a WWW object
        WWW www = new WWW("http://www.takohi.com/data/unity/assets/easyjson/box.json");
        yield return www;
        Box wwwBox = www.Deserialize<Box>();

        Debug.Log(string.Format("Box with {0} product(s) and dimension {1}.", wwwBox.quantity, wwwBox.dimension));
    }

    public class Product {
        public string name;
        public string description;
        public float price;
    }

    public class Box {
        public Vector3 dimension;
        public List<Product> products = new List<Product>();
        public int quantity {
            get {
                return products.Count;
            }
        }
    }
}

Version 1.2 of EasyJSON is now released.

Changelog:

  • Fix bug making corrupted JSON if application is running where the country is writing floating numbers with comma (,).
  • Method to build a pretty JSON string.

SPECIAL CHARACTER ENCODING/DECODING PROBLEM
EasyJSON is a great library for json serialization. ORM works very well!
However I have a problem with strings containing special characters (unicode and umlaut). Can you suggest some example how to resolve this?

EXAMPLE:
Product product= new Product();
product.name = “王 is nöt wörking”;
stringoutput = Serializer.Serialize(product);
Debug.Log(“Compressed Json:\n” + output);

RESULT OF SERIALIZATION: {“name”:“??? is n??t w??rking”

Hello Masaco and thank you for your reply!
Where did you print the result of your serialization? In the Unity console? Can you try to print it in a UTF-8 encoded file?
I will try to reproduce your bug on my side and see if I can fix it but I will need to also help me. I will do as fast as I can but I will need few days. Still you can contact me by email!

I get AOT error on IOS. Have you tested it on IOS?

We have tested on iOS and it runs perfectly. Is it you who sent us an e-mail with the debug log?
If yes, please try to follow our instructions and let us know. We will help you to fix that.

We are now facing two issues:

  • EasyJSON can raise some AOT errors for iOS environment.
  • EasyJSON is not working with Visual Studio.

We will fix as soon as possible these issues. In the meanwhile, for those who bought EasyJSON and are facing these issues, we will offer you one of our other assets. Please contact us.

Takohi, I just purchased EasyJSON to implement serialization for saving / loading in a Windows Store app. It was very easy to use and in 10 minutes everything was good to go.

There are a few issues with the plugin for Windows Store Apps, here is a report of the compatibility that may help your development of the fixes:

Use Shared Projects to Share Code - Xamarin | Microsoft Learn

Keep up the good work.

Hello berzerk. Thank you a lot, this tool is very helpful!

Hi Takohi,

I love your plugin. Working great on Windows for developing and on Android. But now I want to build the iOS version and got an AOT error. Just saw this thread and your answer.
Is there a workaround or an update available yet?

Since I would like to use Umlaute in my project later, I’m also interested in the answer to the other question above.
Do Umlaute work already or is there an update planned?

Thanks

I am sorry for all the inconveniences. Unfortunately, today, as far as I know, there is no workaround.
For the encoding issue, I will try to do an update as soon as possible. For the AOT issue, I will do my best.

Sorry again.

Hi Takohi,
The asset is looking great, but are you still planing to fix the AOT issue for iOS?
Thanks

1 Like

Just wanted to say that EasyJSON is the bomb! No seriously, I’ve looked at several different options for parsing and generating JSON files in Unity, and EasyJSON was the easiest to adopt, and it just flipping worked. Many of the other options I looked at don’t even do object serialization. Like, you had to do the serialization of an object yourself by specifying each property to be serialized. (Take a look at SimpleJSON for an example…yucky).

There’s just one thing I’d like to see added to EasyJSON though. I’d like to be able to have a public property on a serialized object, that is flagged to not be serialized. Is that currently possible, or can that be added?

Hello,

Sorry for the late reply. Unfortunately, I don’t have so much time right now so people will need to wait. But I would be happy if someone can help me to fix it.

I’m very glad you like the assets. Unfortunately, this is currently not possible because to serialize an object, they need to be serializable, therefore flagged serializable. But I will add your recommendation to the todo list. Maybe for a future release. Thank you!

Hello everybody and sorry for being late!

I just published an update for EasyJSON that fix the issue for iOS and probably for some other platforms too! But first, it needs to be reviewed by the Asset Store team before being released.

If you don’t want to wait, feel free to contact me with the invoice number and I will send you the updated package!

Again, truly sorry for the inconvenience.

EDIT:
It has been released and now available on Assets Store.

Hi Takohi,

The latest version of EasyJSON introduces serialization errors with animationcurves. In my case at least, public animations curves are not rebuilt. This was working without any issues in the previous version.

Hello.
No luck, the animation curves serialization was what was making the plugin not compatible with iOS devices… So I removed this support in order to target more platforms.

OK… damn, just what I was using for my iOS game… Back to manual coding then.

Sorry for the trouble. But this doesn’t require too much effort to make it work:

  • Create your custom class that includes all parameters you want to save from a animation curves instance.
  • For saving, copy the values from the animation curves instance in the members of your custom class.
  • Serialize your custom class.
  • Deserialize when you need.
  • Copy back the values in animation curves.

Yeah, that’s what I was thinking as well.

Thanks for the reply.