How can I convert a .txt file into a JavaScript object? - json

I am just out of bootcamp and not familiar with .jl files. I read a solution on stack overflow to convert the .jl files into .txt and the files look like JSON syntax - but I am not experienced enough to say it absolutely is JSON!
The .txt file looks like this - if I wanted to access this file with FE React.js framework and only the product_id/ price / product_imgs_source - is there a method to do this? I can use the data simply by hard-coding it into an array and using it as front-end data and it works - but I am looking for a method that helps me map through this .txt data so a data-transformation method from .txt to .js
{"product_categories_mapped": [24]
"product_id": "ny221a00q-n11",
"price": "84.99",
"product_title": "some description",
"product_imgs_src": ["https://some.jpg"],
"images": [{"url": "https://some.jpg",
"path": "some.jpg",
"checksum": "10f6a0dc3db6b15724cebe9b1cb244be"}],
}
When I used the global fetch() method on the data that was a https link from aws s3 db with a .jl file extension - the error was a 403 so I converted the .jl files to a .txt file and would be great if I could use a JavaScript method to access the .txt data - my worst option is to make it work by manually extracting the data and hardcoding it into an array of objects and accessing the information in the front-end, then creating a node-express environment and a mongo-db collection from this data that I have manually extracted - if there is a better way I will be grateful for any suggestions!

Related

What would be the best way to write JSON in a locally stored file in React Native

Im currently working on a new design for a mobile app (only frontend). In the project I need to use states to change the css of a button. If the button has changed, next time the app is refreshed the state should be as you left it.
That is why I have a locally stored JSON file that is structured the same as how the apps current database is. Reading it is no issue, but I can't get the writing to work.
How I read the JSON:
const jsonData = require('../data.json')
function GetBaseState(id){
console.log(jsonData.bases[id].state)
}
How would I go about changing that state in the JSON file?
In order to both of reading and writing Json file , you are able to use react-native-fs. For example by readFile method you can read json file and by writeFile method writing your json file in local storage.
react-native-fs have good documents that you are able to reading that for more information and usage.

How can I use any json or array or any js file in .testcaferc.json?

I have created one file .testcaferc.json that contains all configuration information like browser name, specs, timeouts etc. I want to fetch the configuration data from file so that I have to change the information at only one place
I want to store all these information in single file, I tried, js, json and array. But I can not import all above format files in my .testcaferc.json, when I press Alt+F8 I see the error "Expected a JSON object, array or literal"
Is there any way I can import json, array or js data in .testcaferc.json?
Thanks in advance!!
The JSON format doesn't support any import directives. The TestCafe configuration file (.testcaferc.json) is a simple JSON file. So, the TestCafe configuration file doesn't support such functionality.
To achieve your goal, you can transform the existing .testcaferc.json file before test running: load data from various sources and add/replace values for the appropriate data fields.
Also, there is a suggestion in the TestCafe GitHub repository, which will make your scenario easier to implement. Track it to be notified about its progress.

How to use local JSON assets to simulate API in Scala.js

I'm new to Scala and Scala.js and I want to experiment with handling JSON data. I'd like to simulate a server response by returning the content of a JSON file local to my Scala.js project, parse it and work with the data. What would be the best way to do so? Where should I place these files in my project tree, and how would I get their content?
Say that I have a file called myJSON.json containing something like
[
{
"ress": "AR",
"lastDate": "2017-10-27 09:19:18"
},
{
"ress": "JIM",
"lastDate": "2017-10-27 06:57:15"
},
{
"ress": "JOE",
"lastDate": "2017-09-29 11:57:39"
}
]
Can I place this file somewhere in my project so that I can read this file and then parse its content to use it somehow (could be displayed in the browser, logged to the console, etc...)? I guess I could use a tool such as scala-js or something similar for parsing, but accessing the file content in the first place is what I try to figure out.
Note that I'm using scala-js.
Thanks in advance!
Like others said above, Javascript that runs in the browser in general can't access the local filesystem. There are some exceptions:
The File API lets you access files that the user has selected in the UI using <input type="file" /> or drag-and-dropped into the browser window.
The Filesystem API lets you access files the way you seem to want, but it is non-standard and is not supported in most browsers. It also seems that Scala.js has no typings for it, but I'm not sure.
scala-js-dom has typings for the File API that you can use – search for File and FileList types in its source. Its API mirrors the Javascript API, so you will need to look for how exactly to do this in JS. Then translating it into Scala.js will be easy (or at least a different question).
If the File API does not work for your use case, another option is to use something like json-server to easily serve your JSON files on localhost via HTTP.

Polymer:how to handle csv file upload and convert to json and send to server

i want to handle a requirement in polymer webcomponents where user can upload csv file from ui and csv file can be parsed to json and sent to server ,i searched and found for vaadin upload,looked over the api but i am not sure how to receive the csv file and convert to json and sent to server,can anyone show a jsfiddle of vaadin upload or any other web component to handle this scenario?
First of all, I am wondering why you would not simply do the conversion on the server side.
In this case, you would be able to use the vaadin-upload directly indeed.
Here is a snippet that would upload all files to the example.com server, and only allow CSV files.
<vaadin-upload target="https://example.com/upload" method="POST" accept="text/csv">
</vaadin-upload>
There are plenty of resources on how to convert CSV files to JSON.
Here is a snippet
And here is a node library
If you really wanted to do the conversion client side, then I would suggest to create an element that would embed a vaadin-upload, and convert the Files array to Json before manually calling the uploadFiles method.

Autodesk Forge Viewer Exporter

I am trying to get access to the manifest.json and metadata.json for a converted revit file that has children f2d.
If I convert a revit file. I get a manifest file that has a svf and f2d files
I know that I can open the svf file as a zip and get its manifest and metadata files to pull down all the files that go along with it.
but the f2d files are not zip files in a format that I understand. So my question is what is the f2d format and how can I access its manifest and metadata so that I can use it in the Viewer.
EXAMPLE:
{
"role": "graphics",
"mime": "application/autodesk-f2d",
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6Z3JlZ2JpbWJ1Y2tldHR3ZW50eXNpeC9SZXZpdF9TYW1wbGVfMjAxNi5ydnQ/output/332d9c2c-1bfd-51c1-35c6-aff868a7e5db_f2d/primaryGraphics.f2d",
"status": "success",
"type": "resource"
},
Note 1 this is not a question about how to convert a DWG file directly. Its a question about converting a revit file that has 2D drawings.
Note 2 I am using the version v2 of the API to convert and pull down the converted files.
Something that got suggested to me by one of our engineer's was the following:
The manifest.json.gz and metadata.json.gz are just files in the same location as the f2d file. But if you are using an F2D file in the viewer, why not use the viewer to load it, and then access those using model.getData().metadata and model.getData().manifest.
I haven't tried it on my side, since I don't have anything setup to get the f2d files at the moment, but I thought it was worth the shot to try with you first.
I see from past questions you have been trying to understand the origin of the .sb and bin files you get back, have you been able to do so?