find text in file .JSON [SOLVED]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
deniscalanca
Posts: 11
Joined: 26 Oct 2017 11:30

find text in file .JSON [SOLVED]

#1 Post by deniscalanca » 10 Nov 2017 06:10

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
Last edited by deniscalanca on 13 Nov 2017 07:22, edited 1 time in total.

aGerman
Expert
Posts: 3706
Joined: 22 Jan 2010 18:01
Location: Germany

Re: find text in file .JSON

#2 Post by aGerman » 10 Nov 2017 23:21

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

npocmaka_
Posts: 481
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: find text in file .JSON

#3 Post by npocmaka_ » 11 Nov 2017 03:25

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.

deniscalanca
Posts: 11
Joined: 26 Oct 2017 11:30

Re: find text in file .JSON

#4 Post by deniscalanca » 12 Nov 2017 09:35

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.

aGerman
Expert
Posts: 3706
Joined: 22 Jan 2010 18:01
Location: Germany

Re: find text in file .JSON

#5 Post by aGerman » 13 Nov 2017 05:52

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

deniscalanca
Posts: 11
Joined: 26 Oct 2017 11:30

Re: find text in file .JSON

#6 Post by deniscalanca » 13 Nov 2017 07:13

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.

Post Reply