How do you parse JSON Data in Arduino - c

I want to parse JSON data from a File in Arduino, how can I do this, I am using Arduino Yun.
One other way I was wondering was to run shell script to take unnecessary data out of the file and leave the data that was necessary for parsing with comma separated but some how when I run this command :
Serial.println(p.runShellCommand("more /mnt/sda1/json.txt |grep -o \"[^ ]*$ " ));
I don't seem to get output at the serial Monitor and i'm not able to save the content in a variable.
Please help out with this issue.

C doesn't have built in JSON parsing capability. Your options are to use something like Jsmn, or aJson (arduino JSON) or have your data provider give it to you in a different format if possible.

Related

JMeter: How to decode alphanumeric characters fetched in JMETER response to its valid value?

I have a JMeter test plan which basically downloads a file by breaking it into multiple parts.
However, these parts are received in encoded alphanumeric character format.
For instance, we have a .txt file which is broken down into 2 parts. Each part has an encoded set of characters. I have been successful so far in appending these characters into another file.
Is there a way of restoring the contents of this file ( holding alphanumeric characters) into the original .txt file with its valid contents back again?
e.g. JMeter response: <data> aWJiZWFuLFBhbmFtYSxDb3NtZXRpY </data>
Can someone please suggest the steps to achieve this?
It looks like it is Base64-encoded, you can use __base64Decode() function (can be installed as a part of Custom JMeter Functions bundle using JMeter Plugins Manager)
${__base64Decode(aWJiZWFuLFBhbmFtYSxDb3NtZXRpY,)}
If you don't have possibility or unwilling to use JMeter Plugins you can achieve the same using JMeter's built-in __groovy() function:
${__groovy(new String('aWJiZWFuLFBhbmFtYSxDb3NtZXRpY'.decodeBase64()),)}

Is there any way of storing a command written in prompt into JSON file

I am using ubuntu and i have used a library named as ICLI (interactive command line interface) which lets one build his own prompt. and i want whatever command i write in this prompt to be stored as JSON.
One way of doing so is file write, for which you can try
with open("data_file.json", "w") as write_file:
json.dump(data, write_file)
Here, data is a variable created before writing these lines. data contains whatever information needs to be stored, in JSON format.

How to check whether large command text answer contains a specific string

This is related to u-boot.
I looked at this link (How to test the return of a command in U-Boot CLI) but it doesn't cover what I need. I also checked some other pages related to the 'test' command in u-boot but I can't figure out how to do what I would like. So there it is.
I have a u-boot command on a SBC which returns a set of information as text printed on the screen, where some part are strings representing versions. What I would like is to check whether the command return contains some specific strings to choose automatically what to do.
I have seen a few 'test' command help, but I couldn't figure out how to do this type of check on the text returned by this command. My goal is to have a set of nested ifs to choose in the different cases, or anything equivalent. If regex can be used, they perhaps could be helpful.
Does anybody know how to do this?
Thank you.
In U-Boot's hush shell there is no support for pipes. There is also no command like grep. So there are no means to succeed via U-Boot's built-in shell commands.
If you have access to the source of the command that you are executing, you could change it and use function env_set() to write the relevant data to environment variables and then use test for your purposes.

Extracting and Displaying data from text file in C

I am trying to write a C program that takes in two arguments, either [-url | -phone | -email] and a text file that the user will download from a website.
After the user inputs the flag and the name of the text file, the program is supposed to extract and display the contents based on the regular expression I have developed.
For example, for URL the regex is
/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
I am having a hard time figuring out how I can implement such a task. Do I need to use fork()? How exactly can I read the data from the text file and display back results based on the regex?
Here is the example OUTPUT
$ gcc –o minor1 minor1.c
$ ./minor1
Usage:
./minor1 [-url | -email | -phone] input_file
URL CASE SCENARIO:
$./minor1 -url index.html
https://www.web.edu/
...
http://webpreview.web.edu/
...
httpL//policy.web.edu/
Based on the flag and the input file, this is what it is supposed to return
You may use curl to download the file from the web.
How to download a file from a URL in C, as a browser would?
C program for downloading files with curl
Then you can iterate and parse the data to extract the regex pattern of either url, email or phone.
Try to come out with some code yourself and if there is any problem, post what you did, snippet of the code that failed, and explain your own thoughts on why do you think it failed.

Getting all possible video file data using mediainfo in linux ( using C )

I need to extract all meta data along with play-length information from the video files in pure C .
I goggled and found MediaInfo Library but was not able to find any relevant c sample code .
Is there any other way to achieve this with / without MetaInfo ?
Or can somebody point me to a good sample code of MediaInfo in C
ffprobe which is part of ffmpeg can do a whole lot more.
ffprobe without switches will give some common information
It also has lot of switches of which you can use one at a time [exclusively]
-show_format show format/container info
-show_streams show streams info
-show_packets show packets info
-show_frames show frames info
-show_data show packets data
Try it out.

Resources