Commit graph

14 commits

Author SHA1 Message Date
Wim Taymans
7ce9b0daec spa-json-dump: fix compilation 2025-06-17 18:08:36 +02:00
Wim Taymans
b67226fa0c spa-json-dump: add -i and -s options
Add -i option to change the indentation
Add -s option to generate simplified SPA JSON
2025-06-17 17:27:10 +02:00
Wim Taymans
fa8208eeef tools: make some things configurable
Things like indentation and simplified spa layout are behind an if 0
but wil some option parsing this could be improved.
2025-06-12 17:16:27 +02:00
Wim Taymans
ce390d5b22 spa: add spa_json_object_next
This gets the next key and value from an object. This function is better
because it will skip key/value pairs that don't fit in the array to hold
the key.

The previous code patter would stop parsing the object as soon as a key
larger than the available space was found.
2024-09-16 09:50:36 +02:00
Wim Taymans
feccb882b6 spa: add spa_json_begin
That combines spa_json_init() and spa_json_next, a common thing to do.
2024-09-16 09:50:31 +02:00
Wim Taymans
a9fdc6a408 spa: improve JSON error reporting in spa-json-dump 2024-03-27 15:57:39 +01:00
Wim Taymans
d4581755e6 spa: Improve JSON error reporting
Add struct spa_error_location that holds information about some parsing
context such as the line and column number, error and line fragment
with the error.

Make spa_json_get_error() fill in the spa_error_location instead. Add
some error codes to the error state and use this to add a parsing reason
to the location.

Add a debug function to log the error location in a nice way. Also
add a FILE based debug context to log to any FILE.

Replace pw_properties_check_string() with
pw_properties_update_string_checked() and add
pw_properties_new_string_checked(). The check string behaviour can still
be done by setting props to NULL but the main purpose is to be able to
avoid parsing the json file twice in the future.

When using the old pw_properties_update_string(), log a warning to the
log when we fail to parse the complete string.

Use the new checked functions and the debug functions to report about
parsing errors in the tools and conf parsing.

This gives errors like:

```
> pw-loopback --playback-props '{ foo =  [ f : g ] }'
error: syntax error in --playback-props: Invalid array separator
line:      1 | { foo =  [ f : g ] }
col:      14 |              ^
```
2024-03-27 15:42:29 +01:00
Pauli Virtanen
7f5e0f0425 spa: spa-json-dump: read also from stdin, and report syntax errors
Support reading from stdin and report syntax errors.

Also don't do extra spa_json_enter when inserting a dummy "{" when
parsing files with top-level keys.  In this case the tokenizer is
already "entered" after spa_json_init, and will give parse error when we
are not inserting the closing "}" for the dummy "{".
2024-03-25 21:42:26 +02:00
Barnabás Pőcze
934ab3036e treewide: use SPDX tags to specify copyright information
SPDX tags make the licensing information easy to understand and clear,
and they are machine parseable.

See https://spdx.dev for more information.
2023-02-16 10:54:48 +00:00
Wim Taymans
c46113faa3 json: spa_json_get_string() writes up to len chars or fail 2022-01-04 10:42:32 +01:00
Wim Taymans
016f02616b json: don't escape / 2021-06-24 16:18:59 +02:00
Wim Taymans
826f52344f spa: properly re-encode the keys and string values
Instead of pasting quotes around them.
2021-06-10 16:32:16 +02:00
Andrea Gelmini
47ef2b6b09 Fix typos 2021-04-30 07:40:20 +00:00
Wim Taymans
3c9996aa78 spa: add tool to dump spa json file to plain json 2021-02-13 20:17:27 +01:00