array3.schema.json fileError I get when I do hit and try with wrong pathsFolder stricture
I have array2.schema.json which is a schema and I want to refer this schema in array3.schema.json file.
I have tried file:/// absolutepath//array2.schema.json but I want to use the relative path.
So instead of file:///D://GIT_Repo//IOTRemoteLab_Sharma_Shubham//D1//D1_1//array2.schema.json, I want to use something like file:///D1//D1_1//array2.schema.json so that I can always validate using array2.schema.json if both are together in a folder.
If the file is in the same directory, just use the filename on its own: { "$ref": "array2.schema.json" }
Related
I need to delete certain entries from nested Json files. As far as I know, I cant just delete them from the json file directly, so my next choice would be to load them into a pyspark dataframe, delete the entries there, create a new json with the same schema (& preferably the same name) and replace the old json file. I have extracted the schema into a json file, is there a way to write the dataframe back into a json file, somehow parsing the extracted schema?
Thanks!
Spark DataFrameWriter also has a method mode() to specify SaveMode; the argument to this method either takes below string or a constant from SaveMode class.
overwrite – mode is used to overwrite the existing file, alternatively, you can use SaveMode.Overwrite.
append – To add the data to the existing file, alternatively, you can use SaveMode.Append.
ignore – Ignores write operation when the file already exists, alternatively you can use SaveMode.Ignore.
errorifexists or error – This is a default option when the file already exists, it returns an error, alternatively, you can use SaveMode.ErrorIfExists.
df2.write.mode(SaveMode.Overwrite).json("/tmp/spark_output/zipcodes.json")
I'm using the TJsonDataObjects Delphi component (https://github.com/ahausladen/JsonDataObjects). I am using it as the data store for what is is displayed in a editable TreeView. In the treeview I store the "path" using a JsonPath string. When the user modifies the values in the Treeview, the path property allows me locate the record by path and modify it via the component path property.
My issue is when a user wants to delete a record, I need to remove it from the JSON file. It does note seem like there is a simple way to do this via its "path. I expect I could trim off the item from the path to gets it parent and then delete it by "name" or "index" if an array. I was hoping there might just be an easier way before I start to code this up.
On a similar node, I didn't find any way to extract the text path of a given item. While it can modify or locate a node by path, there does not seem to be a way to get the actual path so I'm doing that manually as I parse the JSON file (yuck). Anyone have a better solution?
For example, this is the path of the "value" property in the JSON below: Level1.Level2.Level3
{
"Level1": {
"Level2": {
"Level3": "value"
}
}
}
In TJsonDataObjects you can set the path with:
Json.Path['Level1.Level2.Level3'] := "value";
//or
Json['Level1']['Level2']['Level3'] := "value";
Or retrieve it with:
prop := Json.Path['Level1.Level2.Level3'];
// or
prop := Json['Level1']['Level2']['Level3'];
So if you want to remove Level3, it would be nice if there was some simple function like Json.DeletePath('Level1.Level2.Level3');. As far as I can tell, there is nothing that does this. Since this is a very complex unit, I thought someone might have an easy answer that I overlooked. I have coded a way around this (as described above).
As to the second question, while you can access a value by its path, there is no function to "return" a path from a given node. And yes, I can and do build it as I go along, it would be handy as that way it remains consistent in its format of the JsonPath.
I'm able to successfully generate JSON file from Maximo however I would like to modify the JSON before it gets generated. Like below is the sample JSON that gets generated in Maximo,
{"lastreadingdate":"2020-01-30T16:48:33+01:00",
"linearassetmeterid":0,
"sinceinstall":0.0,
"lastreading":"1,150",
"plustinitrdng":0.0,
"sincelastinspect":0.0,
"_rowstamp":"568349195",
"assetnum":"RS100003",
"active":true,
"assetmeterid":85,
"lifetodate":0.0,
"measureunitid":"KWH",
"metername":"1010",
"remarks":"TESTING JSON"}
I need the JSON to be generated as below ,
{"spi:action": "OSLC draft",
"spi:tri1readingdate":"2020-01-30T16:48:33+01:00",
"spi:tryassetmeterid":0,
"spi:install":0.0,
"spi:lastreadingTx":"1,150",
"spi:intrdngtrX":0.0,
and so on...}
Basically I need to change the target attribute names and prefix "spi" Below is the error occuring in JSON Mapping .
You're not specifying how you generate the JSON file but I'll quickly explain how you can achieve this:
As Dex pointed out, there is a JSON Mapping app in the integration module that you can use to map your outbound object structure's fields to your target structure naming.
You define your JSON structure on the JSON Mapping tab by providing a JSON sample.
You then define your mapping with Maximo on the Properties tab, like this:
Reading this IBM doc before jumping right into it should help you a lot:
https://www.ibm.com/developerworks/community/wikis/form/anonymous/api/wiki/02db2a84-fc66-4667-b760-54e495526ec1/page/e10f6e96-435d-433c-8259-5690eb756779/attachment/169224c7-10a5-4cee-af72-697a476f8b2e/media/JSON
After writing a few files for saving in my JSON file in Godot. I saved the information in a variable called LData and it is working. LData looks like this:
{
"ingredients":[
"[KinematicBody2D:1370]"
],
"collected":[
{
"iname":"Pineapple",
"collected":true
},{
"iname":"Banana",
"collected":false
}
]
}
What does it mean when the file says KinematicBody2D:1370? I understand that it is saving the node in the file - or is it just saving a string? Is it saving the node's properties as well?
When I tried retrieving data - a variable that is assigned to the saved KinematicBody2D.
Code:
for ingredient in LData.ingredients:
print(ingredient.iname)
Error:
Invalid get index name 'iname' (on base: 'String')
I am assuming that the data is stored as a String and I need to put some code to get the exact node it saved. Using get_node is also throwing an error.
Code:
for ingredient in LData.ingredients:
print(get_node(ingredient).iname)
Error:
Invalid get index 'iname' (on base: 'null instance')
What information is it exactly storing when it says [KinematicBody2D:1370]? How do I access the variable iname and any other variables - variables that are assigned to the node when the game is loaded - and is not changed through the entire game?
[KinematicBody2D:1370] is just the string representation of a Node, which comes from Object.to_string:
Returns a String representing the object. If not overridden, defaults to "[ClassName:RID]".
If you truly want to serialize an entire Object, you could use Marshalls.variant_to_base64 and put that string in your json file. However, this will likely bloat your json file and contain much more information than you actually need to save a game. Do you really need to save an entire KinematicBody, or can you figure out the few properties that need to be saved (postion, type of object, ect.) and reconstruct the rest at runtime?
You can also save objects as Resources, which is more powerful and flexible than a JSON file, but tends to be better suited to game assets than save games. However, you could read the Resource docs and see if saving Resources seems like a more appropriate solution to you.
I want to edit only one value in an existing JSON file.
Is there any way to do that without parsing and re-writing the whole file? (I use Jackson Streaming API to generate and parse the file, but I'm not sure that Streaming API can do that).
my Example.json file contains the following:
{
"id" : "20120421141411",
"name" : "Example",
"time_start" : "2012-04-21T14:14:14"
}
Example given: I want to edit the value of the "name" from "Example" to "other name".
Not that I know of; either at JSON level, or at file level -- unless length of the values happened to be exactly same, underlying file system typically requires rest of the file to be rewritten from point of change.
You can read and write file using Streaming API, replacing value on the go; see JsonGenerator.copyCurrentEvent(jp) to simplify the task -- it just copies the input event exactly as is. For everything except for replacing particular value, you can call that; and for value, can call JsonGenerator.writeString().
If the file is small and the input value you're looking to replace is unique "enough", and you're open to quick-and-dirty, use apache commons-exec or something to shell out:
bash$> echo '{
"id" : "20120421141411",
"name" : "Example",
"time_start" : "2012-04-21T14:14:14"
}' | sed -e 's/Example/othername/'
outputs:
{
"id" : "20120421141411",
"name" : "othername",
"time_start" : "2012-04-21T14:14:14"
}
Use cat file | sed ... if you know the path to the file.
If you really wanted to edit the file in-place, only writing to those bytes you want to change, it's only possible if the data you are writing will not overwrite subsequent data in the file. You are much better off going with one of the solutions above.
Suppose the JSON file were massive (>1GB?), then would this technique make sense? NO, what the heck are you doing with a JSON file that big? Split it up! But for sake of argument...
You really want to do it, so you hook into a JSON parser to keep track of the byte offset within the file and be able to tie that back to the object representing the JsonNode you will be manipulating. You might end up writing your own parser at this point; JSON grammar is intentionally simple. Then you'd just open the file, skip to that offset, and write the JsonNode data... unless it will overwrite something after it (do you pre-populate the file with buffer of space after every value, just in case? hmmm... this is starting to sound like a database problem). In that case, you'll end up rewriting the entire rest of the file as the larger value "pushes" everything else downward. Not a big deal if the edits are always near the end of file. But if they are random, your performance is doomed. You'll bottleneck serializing writes.