Jump to content

creating .json file


Recommended Posts

There does not appear to be anything standard about that 'normal' file. I don't think I've ever seen such a file before.

To give you a clear picture of the complexity of what you are asking, and why drjd is quite right....just looking at that example I would assume the following about your file:

  • The entire file is a single json object
  • The first line is the 1 and only key within that object
  • there is a CRLF between the key and its value
  • The rest of the file is the value of the single key
  • The single element is itself an object
  • This object consists of key-value pairs separated by "-" and delimited by CRLF
  • Every value is a string
  • Your file cannot contain strings which contain CRLF

Following these rules, your json output would be:Ā 

{"Details": {"Name":"abc", "Organization": "anonymous", "Location": "xyz"}}

If that is what you want, then my only answer is that you will have to procedurally parse the entire file from a string and construct the json object manually.

If that is not what you want, then you should figure out the rules for your "normal simple" file. Once you figure out the rules, you will still have to manually write the code because that isn't a standard computer-parse-able format that I am aware of.

If there are no rules, then you may need to consider a different strategy for whatever it is you are actually trying to accomplish. For example if you are making your files into json to make them easier for a computer to parse, then you'd be better of just shoving all these "normal simple" text files into elastic search or splunk and never look at them again.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.