Extract a specified data object that resides inside a PDF form field to an external file - json

I am looking for a script to extract a data object nested inside a data object to a new data object. Aside from being able to easily clone the object by creating a new one, while I can also extract one of several objects nested inside an object that includes all its related properties and values, the name associated with the property and values is missing. Hence, I require a script to create a new object containing any one of several names including its related properties and values extracted from the existing object provided below.
{"J Doe Company":{"lastUpdate":"01/05/2023","website":"jdoecompany.com","userID":"jdoe1985#gmail.com","password":"igfndhsi1985","primaryCC":"Discover","secondaryCC":"Capital One","primaryBank":"Chase","secondaryBank":"","sq1":"Year Graduated HS","sa1":"1985","sq2":"","sa2":"","notes1":"Sample password record","notes2":""},"Bob The Builder":{"lastUpdate":"01/05/2023","website":"bobthebuilder.com","userID":"bobthebuilder#gmail.com","password":"bbob1985","primaryCC":"Amazon Visa","secondaryCC":"Mastercard","primaryBank":"Wells Fargo","secondaryBank":"","sq1":"First Girlfriend's Name","sa1":"Kaye","sq2":"","sa2":"","notes1":"Sample password record","notes2":""},"SpongeBob Square Pants":{"lastUpdate":"01/07/2023","website":"spongebobsquarepants.com","userID":"spongebob#gmail.com","password":"spongebob1999","primaryCC":"None/Not Applicable","secondaryCC":"","primaryBank":"None/Not Applicable","secondaryBank":"","sq1":"Year show debuted on TV","sa1":"1999","sq2":"","sa2":"","notes1":"Animated TV show for kids","notes2":""}}

You can run cpdf -output-json in.pdf -o put.json and process the result. The format is described in the cpdf manual.

Upon further trial and error after learning more about how to create and edit an object literal, the script required to add an object along with its key-value properties is as follows:
dsFld =getField("dataSrc");// dataSRC is a hidden field containing a JS object converted to a JSON string
oVendors = JSON.parse(dsFld.value); // oVendors is a JS object
oVendors[event.value]=oVendorsPropValues;//oVendorsPropValues = {key-value pairs}
dsFld.value = JSON.stringify(oVendors);// convert the JS obj back to a JSON string

Related

Manipulate JSON Object Data After Iterating via For Each

Might be a dumb question or a small typo. I'm iterating through a JSON object I loaded in and my goal is to MTL some text deep inside. I'm iterating through a list of objects for a specified code, then I translate the text on a correct match. So Iterate through objects > Match Code > Translate Text
The problem is when I try to alter the object by replacing the text with the translated version, that data isn't changed in the returned data object.
def findMatch(data):
# Search Events
for event in data['events']:
if (event is not None):
pages = event['pages']
for page in pages:
lists = page['list']
for list in lists:
if(list['code'] == 401):
for parameter in list['parameters']:
parameter = checkLine(parameter)
return data
checkLine(parameter) will return a string of the text translated.
I'm guessing parameter isn't connected to the data object which is why it's not working but unsure how exactly it should be written out.
Also any suggestions on how to make this faster/more efficient are welcome.
for i, parameter in enumerate(list['parameters']):
list['parameters'][i] = checkLine(parameter)
Does the trick.

Can I create a custom field with datatype as sobject in the Salesforce platform event?

In the platform event, I only see custom field datatypes with Text, Date, Check​box and Number, but not an sobject type. I need to serialize my own class inst​ance (which has accounts + contact list) and publish the object in json format.
I tried creating a custom text field (with name data__c) and assigned the json serialized object to this field. But, the receiver side is getting the unnecessary quote since it's a string. I want to avoid that and just publish as an object only, can I do that?
Now, at the receiver side the data__c is coming like start and ends with double quotes instead of just an object (which starts with curly brackets) like as follows:
enter image description here
So, one option is the receiver should take these quotes out and treat this as an object or other option sending it like an object itself. Request is, can we send as an object? Please help me here.
Thanks
// custom classes defined for json serialization
class CustomAccount {
String oper;
List<Account> accountList;
List<CustomContact> custContactList;
}
// creating an object
customAccount ca = new CustomAccount();
// My new platform event, with assigning the json serialized data to data__c which a text field
Pltf_Notifications__e eve = new Pltf_Notifications__e();
eve.data__c = json.serialize(ca);
enter code here
You can't create sobject data type for platform events. You can handle the logic from platform trigger if response has sobject type by deserializing the sobject data type. If it matches, you can call other handler classes from here by passing the sobject data and construct your desired format from here, then fires the platform event.

What does it mean when a KinematicBody2D is stored in a JSON file - Godot?

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.

Accessing property from COM object XML Result Set in SSIS Script Task

I am working with an SSIS package that was given. to me. I need to extract XML data from an SSIS variable, but I cannot find a way to do it.
When I hit a breakpoint during runtime in my Script Task, I can hover over the Value property of the variable. This shows me a COM object. When I expand the COM object to view its properties, I see the XML data I need in a property called "xml". How do I get at this property from code?
var xmldata = Dts.Variables["User::MyVariableName"].Value;
//xmldata is a COM object with no properties available at design time
Here is what I have tried:
Writing the value out to a file based on examples I have seen online.
This just writes "System.__ComObject" to the file
Casting the COM object to a MarshalByRefObject. This didn't give me
anymore options for retrieving properties
Setting the COM object to a "dynamic" variable. This gave me a
compile time error
Reflection over the COM object to get its properties
(GetProperties()). The COM object did not support this, so I got back
an 0 length array
Changing the result set from XML to DataSet and filling a DataTable
object. I got back a DataTable with one column and multiple rows of
"System.Byte[]", which is worthless.
None of these things have been successful.
Ok, It looks like I gave up on using "dynamic" too early.
Make sure you add a reference to "Microsoft.CSharp", then do something like the code below:
var data = Dts.Variables["User::MyVariableName"]; //Assuming not null.
var comObject = ((dynamic)data.value);
var propertyValue = comObject.PropertyYouNeed;
Make sure the property you are retrieving from the COM object is spelled correctly. A misspelling will not be caught until run time.

Create a List-type view dynamically from a Json object in MVC3

I have a controller that access a WCF service which returns a Json object (collection). All rows are of same type, but at different calls the row stricture is different (the return object comes from a user-built sql query, executed with executeReader and serialized as Json
So I don't know the row structure upfront.
What I need is an easy way to pass this Json string to something which will generate a view of type list on the fly for it. Doesn't matter formatting, etc, just should be output easily as a table.
Does anyone knows how can I accomplish this?
Another option might be to have something that generate the view on the fly for a IEnumerable of anonymous objects (since using this I could convert the json to a list of anonymous)
EDIT
I found something that does pretty much what I need, except it display metadata about passed object.
It is preetyPrint.js, and I integrated it in my page as below:
In my controller I set the result json object to ViewBag.Result, and in the view I used this code:
<script src="#Url.Content("~/Scripts/prettyprint.js")" type="text/javascript"> </script>
<div id="resultGrid"></div>
<script>
var resultObject = #Html.Raw(ViewBag.Result);
var ppTable = prettyPrint(resultObject);
document.getElementById('resultGrid').appendChild(ppTable);
</script>
Does anyone knows such script that actually "dump" the data instead of metadata?
Thanks.
You should create a class to deserialize to if you know the properties of the row. Then use the JavaScriptSerializer class to deserialize to a list of your new class you created. Then you can take a look at the WebGrid class to output the HTML, or just manually iterate over the property metadata in your view.
Creating a custom class will provide you the ability to use metadata to control formatting or other display attributes of the output.
If you cannot create a custom class, you can always use Json.NET or the JavaScriptSerializer to deserialize to a list of dictionary objects or ExpandoObject / Dynamic's or something. Then you would have to manually write something to iterate the keys I think. The ModelMetadataProvider in MVC may be able to handle these allowing you to just iterate the properties in your view code.