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
find text in file .JSON [SOLVED]
Moderator: DosItHelp
-
- Posts: 14
- Joined: 26 Oct 2017 11:30
find text in file .JSON [SOLVED]
Last edited by deniscalanca on 13 Nov 2017 07:22, edited 1 time in total.
Re: find text in file .JSON
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
https://stedolan.github.io/jq/download/
Steffen
Re: find text in file .JSON
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:
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.
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"
If there's no browser.show_home_button object it will return nothing.
-
- Posts: 14
- Joined: 26 Oct 2017 11:30
Re: find text in file .JSON
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.
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
I see. Maybe FINDSTR would be an option in your case.
Steffen
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
-
- Posts: 14
- Joined: 26 Oct 2017 11:30
Re: find text in file .JSON
Steffen very very good, exactly what I needed, thank you very much.aGerman wrote:I see. Maybe FINDSTR would be an option in your case.SteffenCode: 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