- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert JSON string into Lua table?
When working with JSON we generally need to decode JSON into a string or maybe encode a string into JSON. Both of these processes of converting the string into a JSON or the opposite are seen frequently.
While Lua doesn’t provide an official library to do the same, we can still make use of the third party libraries.
There are many third party libraries that we can make use of, out of these the most common one is the json-lua library which can be located on this link.
We can either clone the repository on our local machine and then install it or we can simply install it with the help of the luarocks
Enter the following command in your terminal −
luarocks install json-lua
Now, json-lua installed on the local machine, we can make use of the functions it provides.
Example
Consider the example shown below, where we will convert a JSON string into a Lua table, and explore different functions it provides to do so.
JSON = require("JSON") local t = { ["name1"] = "value100", ["name2"] = { 1, false, true, 23.54, "a \021 string" }, name3 = JSON:null } local encode = JSON:encode (t) print (encode) local decode = json:decode( encode )
Output
{"name1":"value100","name3":null,"name2":[1,false,true,23.54,"a \u0015 string"]}
- Related Articles
- How to convert a JSON string into a JavaScript object?
- How to Convert Perl Compatible Regular Expressions (PCRE) into Lua
- How to convert a string to int in Lua programming?
- How to convert string to JSON using Python?
- How to convert JSON string to array of JSON objects using JavaScript?
- How to convert JSON data into a Python tuple?
- How to convert JSON data into a Python object?
- Convert JSON array into normal json in JavaScript
- How to convert JSON results into a date using JavaScript?
- How can we convert a JSON string to a JSON object in Java?
- How to Convert MySQL Table Field Type from BLOB to JSON?
- Insert JSON into a MySQL table?
- How we can convert Python objects into JSON objects?
- How to convert a JSON string to a bean using JSON-lib API in Java?
- How to Encode and Decode JSON and Lua Programming?
