NodeJS Reading and Writing to WordPress PHP via Rest API

I developed NodeJS program that can read and write to WordPress Rest API. I’m having problem of reading or writing properly the data in NodeJS and WordPress and vice versa.

NodeJS Writes JSON Objects to WordPress Rest API

Any JSON String[] or Object[], will be saved into serialized PHP string by WordPress.

Surprisingly, when NodeJS read the data save in serialize string, NodeJS can read it as JSON object without needs to call JSON.parse().

However JSON Object, will be saved as string by WordPress but still follows JSON string format.

As the JSON Object is saved as string, when NodeJS read the data via WordPress Rest API, NodeJS has to call JSON.parse() to convert it back into JSON Object.

Examples of JSON Object saved by WordPress Rest API

How To Have Consistency?

By having JSON arrays save as PHP serialize string and JSON object as string in PHP, I need to have do extra checking or conversion by calling JSON.parse()

Another possible solution is to call JSON.stringify() to JSON arrays so it is saved as string at PHP. However, it is still extra step that we need to do and it doesn’t solve the problem stated above where there is no consistency.

So, in short there is no possible solution to have consistency, we still need to do extra step as mentioned above.