Why Would You Use {JSON}?

Tags: json, backend, data
Published: 2020-05-13 15:00:45

# Why Would You Use JSON?

So, here we go... As this is my first post around here, maybe it would be nice to present myself, and probably from a work perspective, the most resumed glance you can have of me, would come from my [LinkedIn](https://www.linkedin.com/in/magalhaes-andre/).
And for the ones lacking time to take a look, until this day () i've been mainly a back-end developer (leave in the comment section how you write back end/back-end/backend). This means that i've dealed a lot with Java, frameworks, APIs and microservices, some devops too.
Now that i'm introduced, let me ask you: 
 
_Why Would You Use JSON???_

## Back-end at Its Finest

Back-end softwares have in general one important task, that in most cases are the core of it:

__DEALING WITH THE DATA__

And _how_ would i do that? It's up to you actually:
- Will you need a database? (Most of the times, this is a yes.)
- Will you be talking to another API(Application Programming Interface / A program to talk to.)?
- Will you only do a calculation over variables passed to you?

Whatever the scenario is, it's probably a data dealing scenario. So what this means essentialy?
It means two things:

1. You'll have to receive that data somehow (Input)
2. You'll have to send this data somewhere (Output)

_There are variations to this complex formula, but in essence..._

## Input?

The entrance to your application, the front door, the main way of taking a chat with your great logic state of the art production.

You can build it just anyway you'd like. But...

Maybe you will agree with me on this:

Every door has a resemblance to one another. Probably will have some mechanism to open it. Maybe anyone can open it, maybe it needs some special access (keys/tokens), but it makes sense that most doors have a similar look. So, wouldn't be awesome if there existed some magical pattern that _(almost)_ everyone uses and makes communication such a common matter into development?

__IT EXISTS__

## Is JSON the One?

Nope, at least, it surely wouldn't be the only option, that's for sure, we already had/have some other options pretty common on defining communication. Between them, the one that stand out more and probably the most common besides JSON would be:

## XML (Or: Why You're Not Using JSON)

Just kidding (not so much), XML stands for Extensible Markup Language. What does it means? It means that this language has some set of rules for creating a pattern readable determining how to markup information that will be read into your application.

_What rules are those?_

For a further look and even for starters i would recommend [to follow this steps.](https://www.w3schools.com/xml/) But! If you just want a glance into what a XML file would be, here you go!

```
<?xml version=1.0>
    <PERSON>
        <HEIGHT>1.98</HEIGHT>
        <WEIGHT>100</WEIGHT>
        <NAME>Vince Carter</NAME>
        <POSITION>SG/SF</POSITION>
    </PERSON>
</xml>
```
Does the above seems nice to read? Maybe, since there is a relative low quantity of information, but there are more readable options, like:

## JSON 

Here, the same example would look something like: 

```
{
    "person": {
        "height": 1.98,
        "weight": 100,
        "name": "Vince Carter",
        "position": "SG/SF"
    }
}
```

At least for me it is a considerable number of times more readable and less tiring, just by removing the need of starting a attribute and needing to end it with itself and a slash up front.

The JSON notation reflects much more of a object representation would be, and even on contexts that are not Object Oriented the transport of the message itself becomes much more clearer and simpler than the XML option.

## Oh Well, But i Prefer XML/ I Work in a Old School Codebase

Well, no problem then, as all of the tools we have for coding, they all face the most common discussion that generally sounds as "should i use this?/should i use that?":

_Use what makes sense to your project._

I think this could be a constant with no effort.

Do you want to be the only person using json while every other service/section of your code is expecting a xml? (Please, answer no.)

Surely JSON seems like a cleaner option, but it doesn't mean it is the only one, it serves for communication, and communication has the sole purpose of being understood (at least in computing).


_Thanks for reading it this far!_

_[magalhaes.getGithub()](https://github.com/magalhaes-andre)_