Convert string imported from JSON to table in Lua - json

I want to convert the string "balm" to a table. Balm was imported from a JSON File using dkjson
balm =
{
"a": "test"
"b" : { "test1":1, "test2":2, "test3":3},
"c" : { "test4: 4, "test5": "/path/to/folder"}
}

Like in the comment wrote, it is easy, if you follow the datatype rules.
Example using NeoVIM...
...it will output "test" under the nvim status line.

Related

Compare two Json files using Apache Spark

I am new to Apache Spark and I am trying to compare two json files.
My requirement is to find out that which key/value is added, removed or modified and what is its path.
To explain my problem, I am sharing the code which I have tried with a small json sample here.
Sample Json 1 is:
{
"employee": {
"name": "sonoo",
"salary": 57000,
"married": true
} }
Sample Json 2 is:
{
"employee": {
"name": "sonoo",
"salary": 58000,
"married": true
} }
My code is:
//Compare two multiline json files
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
//Load first json file
val jsonData_1 = sqlContext.read.json(sc.wholeTextFiles("D:\\File_1.json").values)
//Load second json file
val jsonData_2 = sqlContext.read.json(sc.wholeTextFiles("D:\\File_2.json").values)
//Compare both json files
jsonData_2.except(jsonData_1).show(false)
The output which I get on executing this code is:
+--------------------+
|employee |
+--------------------+
|{true, sonoo, 58000}|
+--------------------+
But here only one field i.e. salary was modified so output should be only the updated field with its path.
Below is the expected output details:
[
{
"op" : "replace",
"path" : "/employee/salary",
"value" : 58000
}
]
Can anyone point me in the right direction?
Assuming each json has an identifier, and that you have two json groups (e.g. folders), you need to compare b/w the jsons in the two groups:
Load the jsons from each group into a dataframe, providing a schema matching the structure of the son. After this, you have two dataframes.
Compare the jsons (by now rows in a dataframe) by joining on the identifiers, looking for mismatched values.

Knime JSON transformer - Adding an attribute to a JSON object

I have converted some columns to JSON using the columns to json node. The output from that is:
{
"Material" : 101,
"UOM" : "GRAM",
"EAN" : 7698,
"Description" : "CHALK BOX"
}
I would like to add the value of the material property as a key to each JSON object. So, my desired output is:
"101": {
"Material" : 101,
"UOM" : "GRAM",
"EAN" : 7698,
"Description" : "CHALK BOX"
}
I have tried entering the following expression in the JSON transformer node but all I get is a question mark in the new column it generates:
$Material$:{"Material":$Material$,"UOM":$UOM$,"EAN":$EAN$,"Description":$Description$}
I have also tried replacing the $Material$ with "Material" but got the same result.
How would I go about this, please?
In case you convert the Material column to String (for example with String Manipulator), you can easily configure the Columns to JSON:
As you can see the Data bound key is the important part.
The String Manipulator node configuration (string($Material$)):
I finally managed to solve this by a different method.
I split the JSON data into several columns, then used the join function to create a string in the required order. I put the resulting string through the string to JSON node to create the new JSON object.
Thanks for all your tips and comments !

Is there a JSON format for editing JSON?

I'm wondering if there is a JSON format for editing JSON ?
eg if I had some json
{ "first name" : "Joe" }
and + another json file
{ "action" : "add",
"dest" : "root" -- json pointer maybe
"value" : { "surname : "Blogs" }
}
would get me =
{ "first name" : "Joe", "surname : "Blogs" }
similarly a delete , and change ..
Is there a JSON format that does this? It may be part of a noSQL db or may not be or some javascript library - but i'm not after a JS library more is there a JSON format to do this, One would assume someone has done this before!
It doesn't work like that. JSON is just a data-interchange format (http://www.json.org/). There is no transactional semantic or anything that goes with it.

Controlling JSON output format

A reverse to the question asked at How to format Json output ...
EclipseLink makes JSON output code from JAXB objects like this:
{
"test" : {
"count" : 10,
"text" : "Craig"
}
}
How do I make it put quotes around the number?
Thanks!

Extracting complete JSON object from mongo db object

My fetched DBObject looks like following
{ "_id" : { "$oid" : "50c28ac1de86acf0bdfbeca0"} ,
"schedule" : { "startAt" : 1354926785198 , "endAt" : 1391155200000 , "repeatForever" : true , "interval" : 3600} , "destination" : "Storage-East"}
I want to extract JSON string sans "_id" so that I can deserialize it back to my Java object. If I use following I can remove the '_id' field and it is fine to get the Java object back from JSON String. Is there any other elegant way of doing this ?
dbObj.removeField("_id");
String jsonString = dbObj.toString();
// Now readValue from the json string
thanks.
Instead of removing the data afterwords, just use results projections. You simply remove the _id by using the result projections in a find statement:
//find all documents where destination equals Storage-East, but exclude _id from result set
db.inventory.find( { "destination": 'Storage-East' }, { _id:0 } )
You can find the documentation http://docs.mongodb.org/manual/core/read-operations/#result-projections.