Page 1 of 1
find text in file .JSON [SOLVED]
Posted: 10 Nov 2017 06:10
by deniscalanca
Hello, my name is Denis, I live in Brazil, I am trying to mount a batch file to return me if a certain text exists in a .JSON format file, here is a piece of text that I am trying to capture:
{
"browser": {
"show_home_button": true
},
I just want to know if the "show_home_button" line exists: true, I already tried in several ways and I could not, could anyone help me?
OBS: Sorry for the bad english
Re: find text in file .JSON
Posted: 10 Nov 2017 23:21
by aGerman
JSON is a markup language that always has a certain structure. It's most likely ambiguous to process JSON using textual searching or regular expressions. I remember that I used a small 3rd party utility called jq in the past.
https://stedolan.github.io/jq/download/
Steffen
Re: find text in file .JSON
Posted: 11 Nov 2017 03:25
by npocmaka_
what's the problem with FIND and FINDSTR ?
you need to parse the content as JSON you can try this -
https://github.com/npocmaka/batch.scrip ... ractor.bat.
The script (still) has no proper help message so what you need to do is something like this:
Code: Select all
call jsonextractor.bat "json.txt" "browser.show_home_button"
I have no ide what is the parrent object of the browser so you'll have to add it.You can use also arrays in the expression.
If there's no
browser.show_home_button object it will return nothing.
Re: find text in file .JSON
Posted: 12 Nov 2017 09:35
by deniscalanca
My intention is just to check if there is this "show home button": true in the file.
The file in question is Secure Preferences located at "%LocalAppData%\Google\Chrome\User Data\Default\Secure Preferences"
My intention is to use this file as a parameter to set some google chrome settings on devices outside the domain controller, by default there is no piece of text without a file.
OBS: I do not know if this is giving to understand what I am writing, my English is limited and I use Google Translate.
Re: find text in file .JSON
Posted: 13 Nov 2017 05:52
by aGerman
I see. Maybe FINDSTR would be an option in your case.
Code: Select all
@echo off &setlocal
>nul findstr /rc:"\"show_home_button\":[ ]*true" "%LocalAppData%\Google\Chrome\User Data\Default\Secure Preferences"
if errorlevel 1 (
echo not found
) else (
echo found
)
pause
Steffen
Re: find text in file .JSON
Posted: 13 Nov 2017 07:13
by deniscalanca
aGerman wrote:I see. Maybe FINDSTR would be an option in your case.
Code: Select all
@echo off &setlocal
>nul findstr /rc:"\"show_home_button\":[ ]*true" "%LocalAppData%\Google\Chrome\User Data\Default\Secure Preferences"
if errorlevel 1 (
echo not found
) else (
echo found
)
pause
Steffen
Steffen very very good, exactly what I needed, thank you very much.